3D pyplot散射不透明度按深度

时间:2020-05-22 19:13:17

标签: python matplotlib plot colors scatter

默认情况下,pyplot的3D图具有depthshade=True。但是,在我的代码中,我需要根据样本的属性分别为每个点指定颜色。因此,深度效果消失了。

是否可以将自定义颜色与depthshade行为结合起来?

我对其中一个子图的代码如下:

fig = plt.figure(figsize=(19.2, 10.8), dpi= 80)
handles = []
for i in range(18):
  handles.append(mlines.Line2D([], [], color=colors_azi[i], marker='.'))
ax = fig.add_subplot(231, projection='3d')
for i in trange(len(outs[1])):
  ax.scatter(outs[0][i], outs[1][i], outs[2][i], c=colors_azi[azimuths[i]//2].reshape(1,-1), depthshade=True)
ax.set_title('Azimuth (train)')

请注意,为了避免scatter函数的错误,我正在重塑代码,我很怀疑这可能是原因,但我不知道该怎么做。然后,该图将显示为纯色:

enter image description here

1 个答案:

答案 0 :(得分:0)

好的,所以在某个时候,我发现问题出在每个点上进行散点图以绘制颜色(这也会在交互式窗口中产生超大的滞后行为)。

每次单独的散布呼叫都会应用一次depthsade。最终的代码是:

fig = plt.figure(figsize=(10.8, 10.8), dpi= 80)
ax = fig.add_subplot(111, projection='3d')
c1 = []
for i in range(len(outs[1])):
  c1.append(colors_azi[azimuths[i]//2])
ax.scatter(outs[0], outs[1], outs[2], color=c1)

哪个会产生以下内容:

enter image description here