[英]Scatter plot when x-axis is 1d Numpy array and y-axis is 2d Numpy array
I am trying to plot the relation between two sets x and y, x
is a vector (1d Numpy array) while y
is a 2d Numpy array, and their values are float numbers. 我试图绘制两组x和y之间的关系, x
是一个向量(1d Numpy数组),而y
是2d Numpy数组,它们的值是浮点数。 Each element from the vector x
corresponds to 1d vector from y
(to be specific the i-th element in x corresponds to the i-th column form y). 向量x
每个元素对应于y
1d向量(具体来说,x中的第i个元素对应于第i列形式y)。
x=np.array([0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.10,0.11,0.12,0.13,0.14,0.15])
and its shape is (15,) 它的形状是(15,)
y
shape is (1000, 15) y
形状是(1000,15)
And here what I have done: 在这里,我做了什么:
fig, ax = plt.subplots()
for i, x in enumerate(x):
ax.scatter(x,y[:,i])
plt.show()
ValueError: x and y must be the same size ValueError:x和y的大小必须相同
A scatter plot places points that each have 1 x- and 1 y-value. 散点图放置的点分别具有1个x和1个y值。 You just tried to plot points that that have 1 x- and 1000 y-values. 您只是试图绘制具有1个x值和1000个y值的点。 Of course python doesn't know what to do with that. 当然,python不知道该怎么办。 You can try to fill out the necessary x values. 您可以尝试填写必要的x值。 Also try to avoid double usage of x: 还应尝试避免x的重复使用:
fig, ax = plt.subplots()
for i, val in enumerate(x):
ax.scatter([val]*1000,y[:,i])
plt.show()
try this: 尝试这个:
fig, ax = plt.subplots()
ax.scatter(x,y[0,:])
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.