Matplotlib - Wrong normals on a 3D chart

PROBLEM


When using matplotlib and building three-dimensional bars on a chart, I got the wrong normal values ​​at some borders.


Example


When I draw a graph of high density cells, with 240 bars, I get this result: enter image description here

See that some facets of some bars are wrong? Lines Z are also erroneous.


ABOUT


I use the latest stable version of Matplotlib and Numpy. My Python version is 2.7.3


MAGAZINES


This is the only warning I get from the console:

RuntimeWarning: invalid value occurring when dividing for n in normals])


Any help is greatly appreciated.


EDIT

With @ Saullo Castro's answer, this is a new timeline: enter image description here

Or, using the sample provided in the answer (see the area with red dots):

enter image description here

, , . - , .

+5
1

zsort='max' ax.bar3d() (. ):

ax.bar3d(xpos,ypos,zpos, dx, dy, dz,  color='b', alpha=1., zsort='max')

, :

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()
+4

All Articles