我正在尝试在matplotlib中的FancyBboxPatch前面绘制一个球体。但是,球体被FancyBBoxPatch覆盖。我的最小工作示例如下:
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import FancyBboxPatch
from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d.art3d as art3d
if __name__ == '__main__':
fig = plt.figure()
axes = fig.add_subplot(111, projection = '3d')
for i in range(7):
for j in range(7):
box = FancyBboxPatch((i, j),
1, 1,
boxstyle = 'square,pad=-0.1',
edgecolor = (0.333, 0.333, 0.333),
facecolor = (0.333, 0.333, 0.333))
#zorder = 0)
axes.add_patch(box)
art3d.pathpatch_2d_to_3d(box, z = 0, zdir = 'x')
u = np.linspace(0, 2 * np.pi, 100)
v = np.linspace(0, np.pi, 100)
x = 0.3 * np.outer(np.cos(u), np.sin(v))
y = 0.3 * np.outer(np.sin(u), np.sin(v))
z = 0.3 * np.outer(np.ones(np.size(u)), np.cos(v))
surface = axes.plot_surface(x + 1, y + 1, z + 5, color = 'red')
#zorder = 100,
#alpha = 1)
axes.set_xlim3d(0, 14)
axes.set_ylim3d(0, 14)
axes.set_zlim3d(0, 14)
plt.show()
产生情节:
在图中,球体完全由FancyBboxPatches覆盖。
正如你在脚本中被注释掉的部分所看到的,我已经玩了关键字参数“alpha”和“zorder”(我不想改变FancyBboxPatches的alpha)来尝试制作球体绘制在FancyBboxPatches之上,但是不成功。
如何在FancyBboxPatches前面绘制球体?或者答案是否与Matplotlib 3D plot zorder issue类似,我应该尝试MayaVi?