Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Matplotlib Streamplot提供起点_Python_Matplotlib_Plot_Valueerror - Fatal编程技术网

Python Matplotlib Streamplot提供起点

Python Matplotlib Streamplot提供起点,python,matplotlib,plot,valueerror,Python,Matplotlib,Plot,Valueerror,我试图将起点添加到流线型图中。我发现了一个使用起点的示例代码;在这个链接中讨论了一个不同的问题,但start_points参数起作用。我从中获取了流线型示例代码(图像、轮廓和字段示例代码:streamplot、demo、features.py)。我不明白为什么我可以在一个代码中定义起点,而不能在另一个代码中定义起点。当我试图在示例代码(streamplot\u demo\u features.py)中定义起点时,出现以下错误: 回溯(最近一次呼叫最后一次): 文件“”,第1行,在 运行文件('C

我试图将起点添加到流线型图中。我发现了一个使用起点的示例代码;在这个链接中讨论了一个不同的问题,但start_points参数起作用。我从中获取了流线型示例代码(图像、轮廓和字段示例代码:streamplot、demo、features.py)。我不明白为什么我可以在一个代码中定义起点,而不能在另一个代码中定义起点。当我试图在示例代码(streamplot\u demo\u features.py)中定义起点时,出现以下错误:

回溯(最近一次呼叫最后一次):
文件“”,第1行,在
运行文件('C:/Users/Admin/.spyder/StreamlineExample.py',wdir='C:/Users/Admin/.spyder')
文件“C:\ProgramData\Anaconda2\lib\site packages\spyder\utils\site\sitecustomize.py”,第866行,在runfile中
execfile(文件名、命名空间)
文件“C:\ProgramData\Anaconda2\lib\site packages\spyder\utils\site\sitecustomize.py”,执行文件第87行
exec(编译(脚本文本,文件名,'exec'),glob,loc)
文件“C:/Users/Admin/.spyder/StreamlineExample.py”,第28行,在
ax1.流程图(X、Y、U、V、起点=起点)
文件“C:\ProgramData\Anaconda2\lib\site packages\matplotlib\\uuuu init\uuuu.py”,第1891行,在内部
返回函数(ax,*args,**kwargs)
文件“C:\ProgramData\Anaconda2\lib\site packages\matplotlib\axes\\u axes.py”,第4620行,在streamplot中
zorder=zorder)
streamplot中第144行的文件“C:\ProgramData\Anaconda2\lib\site packages\matplotlib\streamplot.py”
sp2[:,0]+=np.abs(x[0])
ValueError:形状为(1,)的不可广播输出操作数与广播形状(100,)不匹配

我注意到web上没有太多使用起始点的方法,因此任何附加信息都会有帮助。

和的主要区别在于,第一个使用1D数组作为
x
y
网格,而官方示例使用2D数组

因为明确地说

x
y
:1d阵列,均匀分布的网格

我们可能会坚持使用一维数组。不清楚为什么这个例子与docsting相矛盾,但我们可以忽略这一点

现在,使用1D数组作为网格,
start_points
的工作原理与预期一样,因为它采用了2列数组(第一列x坐标,第二列y坐标)

一个完整的例子:

import numpy as np
import matplotlib.pyplot as plt

x,y = np.linspace(-3,3,100),np.linspace(-3,3,100)
X,Y = np.meshgrid(x,y)
U = -1 - X**2 + Y
V = 1 + X - Y**2
speed = np.sqrt(U*U + V*V)

start = [[0,0], [1,2]]

fig0, ax0 = plt.subplots()

strm = ax0.streamplot(x,y, U, V, color=(.75,.90,.93))
strmS = ax0.streamplot(x,y, U, V, start_points=start, color="crimson", linewidth=2)

plt.show()

堆栈溢出很愚蠢,不允许我在帖子中添加以下链接:。从这里我可以看到起始点所需的输入,但没有太多其他信息。太棒了,谢谢。知道streamplot函数中的错误是因为它不能用x[0]和y[0]数组广播起始点数组,这是因为这些数组应该只有1D,这就更有意义了。
import numpy as np
import matplotlib.pyplot as plt

x,y = np.linspace(-3,3,100),np.linspace(-3,3,100)
X,Y = np.meshgrid(x,y)
U = -1 - X**2 + Y
V = 1 + X - Y**2
speed = np.sqrt(U*U + V*V)

start = [[0,0], [1,2]]

fig0, ax0 = plt.subplots()

strm = ax0.streamplot(x,y, U, V, color=(.75,.90,.93))
strmS = ax0.streamplot(x,y, U, V, start_points=start, color="crimson", linewidth=2)

plt.show()