Issue
I need to do a series of vector plots. I can get any number of plots with matplotlib's quiver routine. The thing is, quiver autoscales each plot, but I need the vectors in each plot to all represent the same scale. For instance, if 10 km/hr is represented by a vector of 1cm in one plot, then 10km/hr should be represented by a 1cm vector in all plots. (I don't really care if the vector is specifically 1cm. That's just an example.) I thought I could make this happen by adjusting the scale argument separately for each plot. But it doesn't seem to work.
For example, I find the maximum speed in the first plot, mxs1
, and then for each plot I do something like
mxspd = np.max(speed[n])
pylab.quiver(x,y,vx[n],vy[n],scale=mxs1/mxspd)
But this does not adjust the lengths of the vectors enough. For instance, in the case I was trying, mxspd
is about one half of mxs1
, so the vectors in plot n
should be about half as long as the ones in the first plot. But the vectors in the two plots have pretty much the same lengths.
Solution
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
x, y = np.mgrid[0:20, 0:25]
u = np.sin(2 *x * np.pi / 20)
v = np.cos(2 * y * np.pi / 25)
fig, (ax_l, ax_r) = plt.subplots(1, 2, figsize=(8, 4))
ax_r.quiver(x, y, u, v, scale=5, scale_units='inches')
ax_l.quiver(x, y, 2*u, 2*v, scale=5, scale_units='inches')
ax_l.set_title('2x')
ax_r.set_title('1x')
See the documentation for explainations of the scale
and scale_units
kwargs.
Answered By - tacaswell
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.