3d bargraph in matplotlib

When I make a 3D chart with four or more values, the graph looks right, but when I try to do this, the three columns become triangles, what happens?

from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111, projection='3d') color_grade_classes = ['#80FF00','#FFFF00','#FF8000', '#FF0000'] for colors, rows in zip(color_grade_classes, [3,2,1,0] ): indexs = np.arange(3) heights = np.random.rand(3) print rows, indexs, heights, colors ax.bar(indexs, heights, zs = rows, zdir='y', color=colors, alpha=0.8) ax.set_xlabel('X') ax.set_ylabel('Y') plt.show() 

generates this:

Triangular bar

but when I increase the number of indexes and heights to 5, I get the following:

Correct bar

+7
source share
2 answers

This is almost certainly a mistake. Trying your sample code gives me the desired result of rectangular bars with any number of points (checked from 1, 2, 3, 5, 15): Example of code working as desired for 3 points

I am running matplotlib version 1.1.1rc, on linux. If possible, try updating it to the latest version. note that

 import matplotlib print matplotlib.__version__ 

will tell you which version you are using.

+1
source

This is because you give him only 3 points. Just change the code to the next one and it should work.

 indexs = np.arange(4) # not 3 heights = np.random.rand(4) # not 3 
0
source

All Articles