代码之家  ›  专栏  ›  技术社区  ›  AlMikFox

在mplot3d的scatter()上获取值时出错:参数xs和ys的大小必须相同。但它们的尺寸一样

  •  1
  • AlMikFox  · 技术社区  · 9 年前

    当我打印它们的类型和尺寸时,它们看起来很完美。我不知道出了什么问题。


    “mat2”是512 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

    有什么帮助吗?

    1 回复  |  直到 9 年前
        1
  •  0
  •   ImportanceOfBeingErnest    9 年前

    xx yy 大小不一样。您需要打印形状,而不是打印长度。

    print(xx.shape)
    

    形状良好 (512, 1) 形状良好 (512,2) 因此 有两列,因此条目数是 xx .

    mat2 yy

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

    当然,对于其他阵列也是如此 z co .