python调用bar3d()绘制前后2个长方体,显示时从前往后看,绝大多数角度不能正常观看前面的长方体(如下图),不知是什么原因?
(1)此角度黑色物体正常显示
(2)此角度黑色物体非常显示
补充一下代码如下:
import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
class Rect:
def draw_pic(self):
fig = plt.figure(figsize=(8, 6), dpi=80)
ax = fig.gca(projection='3d')
pos_x_sec, pos_y_sec, pos_z_sec = 0, 50, 0
size_x_sec, size_y_sec, size_z_sec = 40, 10, 80
color = ["orange"]
self.draw_bar3d(ax, pos_x_sec, pos_y_sec, pos_z_sec, size_x_sec, size_y_sec, size_z_sec, color)
pos_x, pos_y, pos_z = 0, 40, 0
size_x, size_y, size_z = 30, 10, 60
color = ["grey"]
self.draw_bar3d(ax, pos_x, pos_y, pos_z, size_x, size_y, size_z, color)
plt.show()
def draw_bar3d(self, ax, pos_x, pos_y, pos_z, size_x, size_y, size_z, color):
bar_x = np.linspace(pos_x, size_x + pos_x, 1)
bar_y = np.linspace(pos_y, size_y + pos_y, 1)
X, Y = np.meshgrid(bar_x, bar_y)
X, Y = X.ravel(), Y.ravel()
gg = np.linspace(size_z, size_z, 2)
Z = [pos_z, pos_z]
c = color * len(gg)
ax.bar3d(X, Y, Z, size_x, size_y, gg, color=c, shade=True, zsort='average')
if __name__ == '__main__':
rect = Rect()
rect.draw_pic()