Skip to content

3D Stem Plot #6271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor code to work with juggle_axes()
  • Loading branch information
zqliang committed Apr 22, 2016
commit 7256a82b51d3c5b02d6dc99c4cb8b7afbcd13484
65 changes: 15 additions & 50 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,7 @@ def stem3(self, *args, **kwargs):
self.hold(True)

# Extract the required values
x, y, zs = [np.asarray(i) for i in args[:3]]
x, y, z = [np.asarray(i) for i in args[:3]]
args = args[3:]

# Popping some defaults
Expand Down Expand Up @@ -2707,68 +2707,33 @@ def stem3(self, *args, **kwargs):
bottom = 0

stemlines = []
#plot the stemlines based on the value of rotate
for thisx, thisy, thisz in zip(x, y, zs):
jx, jy, jz = art3d.juggle_axes(x, y, z, rotate)

if rotate=='y':
l, = Axes.plot(self, [bottom, thisz], [thisy, thisy], linefmt,
label="_nolegend_")
art3d.line_2d_to_3d(l, [thisx, thisx], zdir=zdir)
elif rotate=='x':
l, = Axes.plot(self, [thisx, thisx], [bottom, thisz], linefmt,
label="_nolegend_")
art3d.line_2d_to_3d(l, [thisy, thisy], zdir=zdir)
elif rotate=='z':
l, = Axes.plot(self, [thisy, thisy], [thisx, thisx], linefmt,
label="_nolegend_")
art3d.line_2d_to_3d(l, [bottom, thisz], zdir=zdir)
else:
l, = Axes.plot(self, [thisx, thisx], [thisy, thisy], linefmt,
label="_nolegend_")
art3d.line_2d_to_3d(l, [bottom, thisz], zdir=zdir)

stemlines.append(l)

#plot the baseline in the appropriate plane
for i in range(len(x)-1):

if rotate=='y':
baseline, = Axes.plot(self, [bottom, bottom], [y[i], y[i+1]],
basefmt, label="_nolegend_")
art3d.line_2d_to_3d(baseline, [x[i], x[i+1]], zdir=zdir)

elif rotate=='x':
baseline, = Axes.plot(self, [x[i], x[i+1]], [bottom, bottom],
basefmt, label="_nolegend_")
art3d.line_2d_to_3d(baseline, [y[i], y[i+1]], zdir=zdir)

elif rotate=='z':
baseline, = Axes.plot(self, [y[i], y[i+1]],[x[i], x[i+1]],
basefmt, label="_nolegend_")
art3d.line_2d_to_3d(baseline, [bottom, bottom], zdir=zdir)

else:
baseline, = Axes.plot(self, [x[i], x[i+1]], [y[i], y[i+1]],

baseline, = Axes.plot(self, [x[i], x[i+1]], [y[i], y[i+1]],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probabyl better to use a LineCollection here. Or at least directly create artist.Line2D.

You should also set the color here to eliminate the need for the setp calls in your examples and tests.

basefmt, label="_nolegend_")
art3d.line_2d_to_3d(baseline, [bottom, bottom], zdir=zdir)
art3d.line_2d_to_3d(baseline, [bottom, bottom], rotate)

#swap x,y,zs arrays to plot markerlines and auto scale
if rotate=='y':
x, y, zs = zs, y, x
elif rotate=='x':
x, y, zs = x, zs, y
elif rotate=='z':
x, y, zs = y, x, zs
#plot the stemlines based on the value of rotate
for thisx, thisy, thisz in zip(x, y, z):

l, = Axes.plot(self, [thisx, thisx], [thisy, thisy], linefmt,
label="_nolegend_")
art3d.line_2d_to_3d(l, [bottom, thisz], rotate)

stemlines.append(l)

markerline, = Axes.plot(self, x, y, markerfmt, label="_nolegend_")
art3d.line_2d_to_3d(markerline, zs, zdir=zdir)
art3d.line_2d_to_3d(markerline, z, rotate)
self.hold(remember_hold)

stem_container = StemContainer((markerline, stemlines, baseline),
label=label)
self.add_container(stem_container)

self.auto_scale_xyz(x, y, zs, had_data)
self.auto_scale_xyz(jx, jy, jz, had_data)

return stem_container

Expand Down