当你调用ax.bar3d()时使用参数zsort='max'可以解决你的问题(见here):
ax.bar3d(xpos,ypos,zpos, dx, dy, dz, color='b', alpha=1., zsort='max')
我使用this other question 的代码修改版本来解决您的问题:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
data = np.array([[0,1,0,2,0],
[0,3,0,2,0],
[6,1,1,7,0],
[0,5,0,2,9],
[0,1,0,4,0],
[9,1,3,4,2],
[0,0,2,1,3], ])
column_names = ['a','b','c','d','e']
row_names = ['Mon','Tue','Wed','Thu','Fri','Sat','Sun']
fig = plt.figure()
ax = Axes3D(fig)
lx= len(data[0]) # Work out matrix dimensions
ly= len(data[:,0])
xpos = np.arange(0,lx,1) # Set up a mesh of positions
ypos = np.arange(0,ly,1)
xpos, ypos = np.meshgrid(xpos+0.5, ypos+0.5)
xpos = xpos.flatten() # Convert positions to 1D array
ypos = ypos.flatten()
zpos = np.ones(lx*ly)*1e-10
dx = 1. * np.ones_like(zpos)
dy = dx.copy()
dz = data.flatten()
ax.bar3d(xpos,ypos,zpos, dx, dy, dz, color='b', alpha=1., zsort='max')
plt.ion()
plt.show()