Discussion:
[Matplotlib-users] streamplot: vectors not pointing in the right direction!
Gabriele Brambilla
2015-05-22 06:50:43 UTC
Permalink
Hi,

I have problems with streamplot

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 posted should run)

Gabriele
Benjamin Root
2015-05-22 13:58:18 UTC
Permalink
The documentation for streamplot:

```
*x*, *y* : 1d arrays
an *evenly spaced* grid.
*u*, *v* : 2d arrays
x and y-velocities. Number of rows should match length of y, and
the number of columns should match x.
```

Note that the rows in *u* and *v* should match *y*, and the columns should
match *x*. I think your *u* and *v* are transposed.

Cheers!
Ben Root


On Fri, May 22, 2015 at 2:50 AM, Gabriele Brambilla <
Post by Gabriele Brambilla
Hi,
I have problems with streamplot
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))
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 posted should run)
Gabriele
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Gabriele Brambilla
2015-05-22 15:14:14 UTC
Permalink
Thanks! you are right!
I didn't notice this detail

Gabriele
Post by Benjamin Root
```
*x*, *y* : 1d arrays
an *evenly spaced* grid.
*u*, *v* : 2d arrays
x and y-velocities. Number of rows should match length of y, and
the number of columns should match x.
```
Note that the rows in *u* and *v* should match *y*, and the columns should
match *x*. I think your *u* and *v* are transposed.
Cheers!
Ben Root
On Fri, May 22, 2015 at 2:50 AM, Gabriele Brambilla <
Post by Gabriele Brambilla
Hi,
I have problems with streamplot
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))
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 posted should run)
Gabriele
------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Matplotlib-users mailing list
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Loading...