3D bar graphs with variable depth #569

Closed
kosma opened this Issue Nov 8, 2011 · 2 comments

Comments

Projects
None yet
3 participants

kosma commented Nov 8, 2011

When attempting to plot a 3D bar graph with the bars having different depths, they are not rendered correctly. Sample code:

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

fig = plt.figure()
try:
    ax = fig.add_subplot(111, projection='3d')
except:
    ax = Axes3D(fig)
for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]):
    xs = np.arange(20)
    ys = np.random.rand(20)
    zs = [z] * len(xs)
    # stagger the first bar a bit - causes rendering problems
    zs[0] += 5

    cs = [c] * len(xs)

    ax.bar(xs, ys, zs=zs, zdir='y', color=cs, alpha=0.8)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

Fix:

diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py
index 65be58e..87fdc2b 100644
--- a/lib/mpl_toolkits/mplot3d/axes3d.py
+++ b/lib/mpl_toolkits/mplot3d/axes3d.py
@@ -1916,7 +1916,7 @@ class Axes3D(Axes):
             vs = art3d.get_patch_verts(p)
             verts += vs.tolist()
             verts_zs += [z] * len(vs)
-            art3d.patch_2d_to_3d(p, zs, zdir)
+            art3d.patch_2d_to_3d(p, z, zdir)
             if 'alpha' in kwargs:
                 p.set_alpha(kwargs['alpha'])
Member

WeatherGod commented Nov 8, 2011

Good catch! I will get this one committed.

Member

pelson commented Aug 19, 2012

closed by #573

pelson closed this Aug 19, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment