【问题标题】:3d scatter plot with color in matplotlibmatplotlib 中带有颜色的 3d 散点图
【发布时间】:2016-12-30 19:45:21
【问题描述】:

我在 python 的 matplotlib 中使用 scatter 3d plot 来绘制以下数据,

      x              y            z        b2
3.28912855713 4.64604863545 3.95526335139 1.0
3.31252670518 4.65385917898 3.96834118896 1.0

当情节为 2d 时,

fig = plt.figure()
ax = fig.add_subplot(111)
line =ax.scatter(x,y,c=b2,s=500,marker='*',edgecolors='none')
cb = plt.colorbar(line)

它生成以下图像,这是完全正确的。

现在,我想绘制 3d 点,代码如下:

fig = plt.figure()
ax = fig.add_subplot(111,projection='3d')
line = ax.scatter(x,y,z,c=b2,s=1500,marker='*',edgecolors='none',depthshade=0)
cb = plt.colorbar(line)

我得到以下情节,这是不正确的,因为颜色应该像以前的情况一样是绿色的(b2 不会改变)。

我错过了什么吗?

【问题讨论】:

    标签: python matplotlib plot colors 3d


    【解决方案1】:

    可能不会。我不知道您使用的是哪个版本的 Matplotlib,但在某些时候,这个问题存在一个错误,显然仍然对我今天使用的版本产生影响,即 1.5.1(查看this question 了解更多信息) .

    根据您的问题调整 @Yann 解决方案应该可以解决该问题。我在电脑上测试了一下,结果如下:

    import matplotlib.pyplot as plt
    from mpl_toolkits.mplot3d import Axes3D
    
    x = [3.28912855713, 3.31252670518]
    y = [4.64604863545, 4.65385917898]
    z = [3.95526335139, 3.96834118896]
    b2 = [1, 1]
    
    fig = plt.figure()
    ax = fig.add_subplot(111,projection='3d')
    line = ax.scatter(x, y ,z , c=b2, s=1500, marker='*', edgecolors='none', depthshade=0)
    cb = plt.colorbar(line)
    
    def forceUpdate(event):
        global line
        line.changed()
    
    fig.canvas.mpl_connect('draw_event', forceUpdate)
    
    plt.show()
    

    入口处和旋转后的地块图像是:

    【讨论】:

      猜你喜欢
      • 2011-07-26
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 2017-09-17
      相关资源
      最近更新 更多