Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

3D bar graphs with variable depth #569

Closed
kosma opened this Issue · 2 comments

3 participants

Kosma Moczek Benjamin Root Phil Elson
Kosma Moczek

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'])
Benjamin Root
Collaborator

Good catch! I will get this one committed.

Phil Elson
Collaborator

closed by #573

Phil Elson pelson closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.