Skip to content

Commit fd98f28

Browse files
committed
FIX: double z-axis draw in mplot3D
When we moved `Axes.draw` to use `Axes.get_children` to get the initial list of artists to draw the zaxis was now in this list (where as it was not previously). The 3D axes use `_axison = False` as `Axes3D` manages the drawing of the axis objects (which must happen before any of the artists). In `Axes.draw` there is a special case to remove the x and y axis from the draw list if `not _axison`. This change is to add a `_get_axis_list` method to the `Axes` base class and override this in the `Axes3D`. This list is looped over to remove all of the `axis` objects that when the axises should not be shown. Closes #4971
1 parent 58cba1f commit fd98f28

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/matplotlib/axes/_base.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -2049,6 +2049,9 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True):
20492049
y0, y1 = ylocator.view_limits(y0, y1)
20502050
self.set_ybound(y0, y1)
20512051

2052+
def _get_axis_list(self):
2053+
return (self.xaxis, self.yaxis)
2054+
20522055
# Drawing
20532056

20542057
@allow_rasterization
@@ -2090,8 +2093,8 @@ def draw(self, renderer=None, inframe=False):
20902093
self.xaxis.set_zorder(2.5)
20912094
self.yaxis.set_zorder(2.5)
20922095
else:
2093-
artists.remove(self.xaxis)
2094-
artists.remove(self.yaxis)
2096+
for _axis in self._get_axis_list():
2097+
artists.remove(_axis)
20952098

20962099
if inframe:
20972100
artists.remove(self.title)

lib/mpl_toolkits/mplot3d/axes3d.py

+11-8
Original file line numberDiff line numberDiff line change
@@ -192,26 +192,29 @@ def set_top_view(self):
192192
def _init_axis(self):
193193
'''Init 3D axes; overrides creation of regular X/Y axes'''
194194
self.w_xaxis = axis3d.XAxis('x', self.xy_viewLim.intervalx,
195-
self.xy_dataLim.intervalx, self)
195+
self.xy_dataLim.intervalx, self)
196196
self.xaxis = self.w_xaxis
197197
self.w_yaxis = axis3d.YAxis('y', self.xy_viewLim.intervaly,
198-
self.xy_dataLim.intervaly, self)
198+
self.xy_dataLim.intervaly, self)
199199
self.yaxis = self.w_yaxis
200200
self.w_zaxis = axis3d.ZAxis('z', self.zz_viewLim.intervalx,
201-
self.zz_dataLim.intervalx, self)
201+
self.zz_dataLim.intervalx, self)
202202
self.zaxis = self.w_zaxis
203203

204204
for ax in self.xaxis, self.yaxis, self.zaxis:
205205
ax.init3d()
206206

207207
def get_children(self):
208-
return [self.zaxis,] + Axes.get_children(self)
208+
return [self.zaxis, ] + Axes.get_children(self)
209+
210+
def _get_axis_list(self):
211+
return super(Axes3D, self)._get_axis_list() + (self.zaxis, )
209212

210213
def unit_cube(self, vals=None):
211214
minx, maxx, miny, maxy, minz, maxz = vals or self.get_w_lims()
212215
xs, ys, zs = ([minx, maxx, maxx, minx, minx, maxx, maxx, minx],
213-
[miny, miny, maxy, maxy, miny, miny, maxy, maxy],
214-
[minz, minz, minz, minz, maxz, maxz, maxz, maxz])
216+
[miny, miny, maxy, maxy, miny, miny, maxy, maxy],
217+
[minz, minz, minz, minz, maxz, maxz, maxz, maxz])
215218
return list(zip(xs, ys, zs))
216219

217220
def tunit_cube(self, vals=None, M=None):
@@ -1718,7 +1721,7 @@ def plot_wireframe(self, X, Y, Z, *args, **kwargs):
17181721
17191722
The `rstride` and `cstride` kwargs set the stride used to
17201723
sample the input data to generate the graph. If either is 0
1721-
the input data in not sampled along this direction producing a
1724+
the input data in not sampled along this direction producing a
17221725
3D line plot rather than a wireframe plot.
17231726
17241727
========== ================================================
@@ -2438,7 +2441,7 @@ def bar3d(self, x, y, z, dx, dy, dz, color='b',
24382441
self.add_collection(col)
24392442

24402443
self.auto_scale_xyz((minx, maxx), (miny, maxy), (minz, maxz), had_data)
2441-
2444+
24422445
return col
24432446

24442447
def set_title(self, label, fontdict=None, loc='center', **kwargs):

0 commit comments

Comments
 (0)