Matplotlib:3D投影中的zorder不起作用

epggiuax  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(362)

我正在用matplotlib绘制一个3d图形,并试图用属性“zorder”来改变一些散点的顺序。具有最高zorder的对象应该放在最上面,但它失败了。下面是我的代码:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(projection= '3d')

coorx = [1,2,3,4]
coory = [1,1,1,1]
coorz = [1,1,1,1]

for i in range(4):
    ax.scatter(coorx[i], coory[i], coorz[i], s = coorx[i]*40, alpha = 1, c = 'orange', zorder = 1)
    ax.scatter(coorx[i], coory[i], coorz[i], s = 2, alpha = 1, c = 'white', zorder = 0)

plt.show()

结果如下:

如代码所示,我指定了zorder较高的橙子点,但它们实际上位于白色点的下方。
我已经在网上搜索并阅读了这份文件,但它们帮不上什么忙。

siv3szwd

siv3szwd1#

有趣。我不知道为什么,但是当用ax.plot而不是ax.scatter调用zorder时,zorder似乎表现得很正常,如下所示:

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(projection= '3d')

coorx = [1,2,3,4]
coory = [1,1,1,1]
coorz = [1,1,1,1]

ax.plot(coorx, coory, coorz, markersize = 10, marker = 'o', alpha = 1, c = 'orange', zorder = 1, linestyle = '')
ax.plot(coorx, coory, coorz, markersize = 1, marker = 'o', alpha = 1, c = 'white', zorder = 0, linestyle = '')

plt.show()

其产生:

变更为

ax.plot(coorx, coory, coorz, markersize = 10, marker = 'o', alpha = 1, c = 'orange', zorder = 0, linestyle = '')
ax.plot(coorx, coory, coorz, markersize = 1, marker = 'o', alpha = 1, c = 'white', zorder = 1, linestyle = '')

收益率

我的猜测是scatter不知道如何处理zorder,但plot知道-但这是一个总的猜测。

相关问题