【问题标题】:Getting value error on scatter() of mplot3d : arguements xs and ys must be of the same size. But they have the same size在 mplot3d 的 scatter() 上获取值错误:参数 xs 和 ys 必须具有相同的大小。但它们的大小相同
【发布时间】:2017-12-02 22:33:17
【问题描述】:

我正在尝试使用 mplot3d 绘制散点图,但 scatter 方法给出了值错误:“xs”和“ys”必须具有相同的大小。 当我打印它们的类型和尺寸时,它们看起来很完美。我无法弄清楚出了什么问题。

这是我的代码的一部分:
'mat2' 是 512 X 4 个已经计算好的矩阵。

mat2 = np.array(mat2)

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
co = []

xx = mat2[:,:1]
yy = mat2[:,:2]
z = mat2[:,:3]
co = mat2[:,:4]

#printing the size and types of the arguments to the scatter()
print(str(len(xx))+str(type(xx))+' '+str(len(yy))+str(type(yy))+' '+str(len(z))+' '+str(len(co)))

ax.scatter(np.array(xx), np.array(yy), z=np.array(z), c=np.array(co), cmap=plt.hot())

这是我得到的输出截图 - ValueError Screenshot

有什么帮助吗?

【问题讨论】:

标签: python-3.x matplotlib scatter-plot mplot3d valueerror


【解决方案1】:

xxyy 的大小不同。您需要打印形状,而不是打印长度。

print(xx.shape)

您将观察到xx 的形状为(512, 1),而yy 的形状为(512,2)。因此yy 有两列,因此条目数是xx 的两倍。

由于您似乎想要绘制mat2 的第二列与第一列的散点图,因此您应该这样创建xxyy

xx = mat2[:,0]
yy = mat2[:,1]

当然,其他数组zco 也是如此。

【讨论】:

  • 感谢您的帮助。非常感谢。
猜你喜欢
  • 2022-01-12
  • 2016-09-17
  • 1970-01-01
  • 2019-08-20
  • 1970-01-01
  • 2016-04-03
  • 2020-02-23
  • 2017-05-30
相关资源
最近更新 更多