Skip to content

Commit c0af471

Browse files
committed
Simplify axes3d implementation.
We can stop adding multiple lines and put in a single `plot`, which also ensures that everything gets the same properties.
1 parent bfd8b53 commit c0af471

File tree

1 file changed

+23
-17
lines changed

1 file changed

+23
-17
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,25 +3319,31 @@ def stem(self, x, y, z, *, linefmt='C0-', markerfmt='C0o', basefmt='C3-',
33193319

33203320
had_data = self.has_data()
33213321

3322-
stemlines = []
33233322
jx, jy, jz = art3d.juggle_axes(x, y, z, zdir)
33243323

3325-
# plot the baseline in the appropriate plane
3326-
for i in range(len(x)-1):
3327-
baseline, = Axes.plot(self, [x[i], x[i+1]], [y[i], y[i+1]],
3328-
basefmt, label="_nolegend_")
3329-
art3d.line_2d_to_3d(baseline, [bottom, bottom], zdir)
3330-
3331-
# plot the stemlines based on the value of rotate
3332-
for thisx, thisy, thisz in zip(x, y, z):
3333-
l, = Axes.plot(self, [thisx, thisx], [thisy, thisy], linefmt,
3334-
label="_nolegend_")
3335-
art3d.line_2d_to_3d(l, [bottom, thisz], zdir)
3336-
3337-
stemlines.append(l)
3338-
3339-
markerline, = Axes.plot(self, x, y, markerfmt, label="_nolegend_")
3340-
art3d.line_2d_to_3d(markerline, z, zdir)
3324+
# Plot the baseline in the appropriate plane.
3325+
baseline, = self.plot(x, y, basefmt, zs=bottom, zdir=zdir,
3326+
label='_nolegend_')
3327+
3328+
# Plot the stemlines based on the value of zdir.
3329+
if zdir[-1:] == 'x':
3330+
lines = [[(bottom, thisy, thisz), (thisx, thisy, thisz)]
3331+
for thisx, thisy, thisz in zip(jx, jy, jz)]
3332+
elif zdir[-1:] == 'y':
3333+
lines = [[(thisx, bottom, thisz), (thisx, thisy, thisz)]
3334+
for thisx, thisy, thisz in zip(jx, jy, jz)]
3335+
else:
3336+
lines = [[(thisx, thisy, bottom), (thisx, thisy, thisz)]
3337+
for thisx, thisy, thisz in zip(jx, jy, jz)]
3338+
linestyle, linemarker, linecolor = _process_plot_format(linefmt)
3339+
if linestyle is None:
3340+
linestyle = rcParams['lines.linestyle']
3341+
stemlines = art3d.Line3DCollection(
3342+
lines, linestyles=linestyle, colors=linecolor, label='_nolegend_')
3343+
self.add_collection(stemlines)
3344+
3345+
markerline, = self.plot(x, y, z, markerfmt, zdir=zdir,
3346+
label='_nolegend_')
33413347

33423348
stem_container = StemContainer((markerline, stemlines, baseline),
33433349
label=label)

0 commit comments

Comments
 (0)