 # Was: [SciPy-user] Plotting vector field + velocity magnitude in background

(Let's discuss the second point in the matplotlib list only.)
Can you try the following code :

import matplotlib.pyplot as plt
import numpy as np
x, y= np.arange(0,2*np.pi,.2), np.arange(0,2*np.pi,.2)
X,Y = np.meshgrid(x,y)
U,V = np.cos(X), np.sin(Y)
plt.pcolor(X,Y,U**2+V**2)
plt.quiver(X,Y,U,V)
plt.show()

If it is what you do want, then you then only need to import your own
data...

···

Le lundi 10 novembre 2008, wbrevis a écrit :

I'm trying to plot one of my experimental data using scipy. Until now,
all the work I did was using Matlab. For one of my normal data-
visualization, I read ASCII or Binary files containing 4 columns: The
first contains the x coordinate, the second the y one, and the third
and fourth columns the velocity in the x and y directions (u and v),
i.e. file= x y u v (ordered in columns). After reading the data in
Matlab, I normally do: pcolor(x,y,sqrt(u.^2+v.^2)), in order to
visualize in colors the velocity magnitude and then quiver(x,y,u,v) in
order to see the associated vectors. I was reading the manual of
scipy, including the plotting tools, but I am a bit lost (too much
information to start). Can somebody help me with suggestions on how to
read data using scipy and the best way to plot (pcolor+quiver)?. What
about the function quiver3d of mlab, can be used for 2d representation
of a flow field, together with surf (also mlab).

--
Fabricio

Fabrice Silva wrote:

I'm trying to plot one of my experimental data using scipy. Until now,
all the work I did was using Matlab. For one of my normal data-
visualization, I read ASCII or Binary files containing 4 columns: The
first contains the x coordinate, the second the y one, and the third
and fourth columns the velocity in the x and y directions (u and v),
i.e. file= x y u v (ordered in columns). After reading the data in
Matlab, I normally do: pcolor(x,y,sqrt(u.^2+v.^2)), in order to
visualize in colors the velocity magnitude and then quiver(x,y,u,v) in
order to see the associated vectors. I was reading the manual of
scipy, including the plotting tools, but I am a bit lost (too much
information to start). Can somebody help me with suggestions on how to
read data using scipy and the best way to plot (pcolor+quiver)?. What
about the function quiver3d of mlab, can be used for 2d representation
of a flow field, together with surf (also mlab).

(Let's discuss the second point in the matplotlib list only.)
Can you try the following code :
import matplotlib.pyplot as plt
import numpy as np
x, y= np.arange(0,2*np.pi,.2), np.arange(0,2*np.pi,.2)
X,Y = np.meshgrid(x,y)
U,V = np.cos(X), np.sin(Y)
plt.pcolor(X,Y,U**2+V**2)
plt.quiver(X,Y,U,V)
plt.show()

If it is what you do want, then you then only need to import your own
data...

If you have a reasonably recent version of numpy, then you can use numpy.loadtxt; if the data file is as simple as it sounds, you can also use numpy.fromfile, even with an older numpy version. Or you can use matplotlib.mlab.load, from which numpy.loadtxt was derived, I believe.