【发布时间】:2014-05-30 23:36:44
【问题描述】:
我正在尝试使用 Matplotlib 绘制一些流线。
到目前为止,我有这段代码,作为绘制 10 x 10 向量场的示例:
def plot_streamlines(file_path, vector_field_x, vector_field_y):
plt.figure()
y, x = numpy.mgrid[-2:2:10j, -2:2:10j]
plt.streamplot(x, y, vector_field_x, vector_field_y, color='y', cmap=plt.cm.autumn)
plt.savefig(file_path + '.png')
plt.close()
这工作正常,但如果我只是改变这一行:
y, x = numpy.mgrid[-2:2:10j, -2:2:10j]
致那个人:
x, y = numpy.mgrid[-2:2:10j, -2:2:10j]
我收到一些错误:
Traceback (most recent call last):
File "Library/Python/2.7/lib/python/site-packages/matplotlib/pyplot.py", line 3224, in streamplot minlength=minlength, transform=transform)
File "/Library/Python/2.7/lib/python/site-packages/matplotlib/axes.py", line 6861, in streamplot transform=transform)
File "Library/Python/2.7/lib/python/site-packages/matplotlib/streamplot.py", line 67, in streamplot grid = Grid(x, y)
File "Library/Python/2.7/lib/python/site-packages/matplotlib/streamplot.py", line 256, in __init__
assert np.allclose(x_row, x)
AssertionError
我不明白如何使用“标准”顺序 x / y,因为我的网格是正方形的。此外,如果我的 x 和 y 尺寸相同,我不知道如何得到这些错误。
任何帮助将不胜感激。
谢谢。
【问题讨论】:
标签: python matplotlib flow