[SciPy-User] problem using numpy arrays with stream plot

Gabriele Brambilla gb.gabrielebrambilla at gmail.com
Fri May 22 05:13:07 EDT 2015


Hi,

I have a problem using bumpy arrays with stream plot.

I want to use a 3d vector field in coordinates (x,y,z) stored in a numpy
array, and plot slices of it with streamplot.

To test it I wanted to use a vector field with arrows pointed up in the z>0
region and pointed down in the z<0 region.


    import numpy as np

    import matplotlib.pyplot as plt

    from math import *



    max = 100

    min = -100





    X = np.linspace(min, max, num=100)

    Y = np.linspace(min, max, num=100)

    Z = np.linspace(min, max, num=100)



    N = X.size



    #single components in the 3D matrix


    Bxa = np.zeros((N, N, N))

    Bya = np.zeros((N, N, N))

    Bza = np.zeros((N, N, N))





    for i, x in enumerate(X):

     for j, y in enumerate(Y):

     for k, z in enumerate(Z):

     Bxa[ i, j, k] = 0.0 #x

     Bya[ i, j, k] = 0.0 #y

     Bza[ i, j, k] = z



    #I take a slice close to Y=0

    Bx_sec = Bxa[:,N/2,:]

    By_sec = Bya[:,N/2,:]

    Bz_sec = Bza[:,N/2,:]



    fig = plt.figure()

    ax = fig.add_subplot(111)

    ax.streamplot(X, Z, Bx_sec, Bz_sec, color='b')

    ax.set_xlim([X.min(), X.max()])

    ax.set_ylim([Z.min(), Z.max()])



    plt.show()


But I obtain something that looks like if I have put Bza = x! I tried to
invert the order of vectors but it is unuseful!

I attach the picture. Do you understand why? (the code I wrote should run)

Gabriele
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150522/c1e4ebe6/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: figure_1.png
Type: image/png
Size: 14785 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150522/c1e4ebe6/attachment.png>


More information about the SciPy-User mailing list