Wrong overlab in bar3d plot

2019-07-23 13:16发布

I've made this 3d bar plot, but I've found a wrong overlap in some bars, as I show in the image below with green circles:enter image description here

The plot is made by:

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d.axes3d import Axes3D
import matplotlib.colors as colors

fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111, projection='3d')    
matrix = np.array([
[84 80 68 56 60 44 55 39 27 29]
[82 67 63 44 47 33 22 19  9  2]
[53 61 48 34  0 16  0  0  0  0]
[48 25  0  0  0  0  0  0  0  0]])

len_x, len_y = matrix.shape
_x = np.arange(len_x)
_y = np.arange(len_y)

xpos, ypos = np.meshgrid(_x, _y)
xpos = xpos.flatten('F')
ypos = ypos.flatten('F')
zpos = np.zeros_like(xpos)

dx = np.ones_like(zpos)
dy = dx.copy()
dz = matrix.flatten()

cmap=plt.cm.magma(plt.Normalize(0,100)(dz))

ax.bar3d(xpos+0.32, ypos-0.3, zpos, dx-0.6, dy-0.1, dz, zsort='max', color=cmap)

ax.set_xlabel('x')
ax.set_xticks(np.arange(len_x+1))
ax.set_xticklabels(['1000','500','100','50','0'])
ax.set_xlim(0,4)
ax.set_ylabel('y')
ax.set_yticks(np.arange(len_y+1))
ax.set_yticklabels(['0.5','1.','1.5','2.','2.5','3.','3.5','4.','4.5','5.'])
ax.set_ylim(-0.5,10)
ax.set_zlabel('z')
ax.set_zlim(0,100)
ax.view_init(ax.elev, ax.azim+100)

Is it a bug? Why some bars are badly overlapping? I'm using matplotlib version 2.1.0 and anaconda python 3.6.3

0条回答
登录 后发表回答