problem using numpy arrays with stream plot
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
participants (1)
-
Gabriele Brambilla