我有时可以将start_points
参数设为streamplot
,但出于某种原因,我通常会收到一些我不理解的错误:
import numpy as np
import matplotlib.pyplot as plt
Y,X = np.mgrid[-10:10:.01, -10:10:.01]
U, V = Y**2, X**2
stream_points = np.array(zip(np.arange(-9,9,2), -np.arange(-9,9,2)))
plt.streamplot(X,Y, U,V, start_points=stream_points)
plt.show(False)
错误:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
----/streamplot.py in <module>()
4 U, V = Y**2, X**2
5 stream_points = np.array(zip(np.arange(-9,9,2), -np.arange(-9,9,2)))
----> 6 plt.streamplot(X,Y, U,V, start_points=stream_points)
7 plt.show(False)
8 plt.savefig('stream.png')
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in streamplot(x, y, u, v, density, linewidth, color, cmap, norm, arrowsize, arrowstyle, minlength, transform, zorder, start_points, hold, data)
3381 arrowsize=arrowsize, arrowstyle=arrowstyle,
3382 minlength=minlength, transform=transform,
-> 3383 zorder=zorder, start_points=start_points, data=data)
3384 finally:
3385 ax.hold(washold)
/usr/lib/python2.7/dist-packages/matplotlib/__init__.pyc in inner(ax, *args, **kwargs)
1812 warnings.warn(msg % (label_namer, func.__name__),
1813 RuntimeWarning, stacklevel=2)
-> 1814 return func(ax, *args, **kwargs)
1815 pre_doc = inner.__doc__
1816 if pre_doc is None:
/usr/lib/python2.7/dist-packages/matplotlib/axes/_axes.pyc in streamplot(self, x, y, u, v, density, linewidth, color, cmap, norm, arrowsize, arrowstyle, minlength, transform, zorder, start_points)
4462 start_points=start_points,
4463 transform=transform,
-> 4464 zorder=zorder)
4465 return stream_container
4466 streamplot.__doc__ = mstream.streamplot.__doc__
/usr/lib/python2.7/dist-packages/matplotlib/streamplot.pyc in streamplot(axes, x, y, u, v, density, linewidth, color, cmap, norm, arrowsize, arrowstyle, minlength, transform, zorder, start_points)
138 # data2grid works properly.
139 sp2 = np.asanyarray(start_points, dtype=np.float).copy()
--> 140 sp2[:, 0] += np.abs(x[0])
141 sp2[:, 1] += np.abs(y[0])
142 for xs, ys in sp2:
ValueError: operands could not be broadcast together with shapes (9,) (2000,) (9,)