10000 Change draw order so that the 3D axis spines are not blocked by gridl… · matplotlib/matplotlib@b75b0e6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b75b0e6

Browse files
Change draw order so that the 3D axis spines are not blocked by gridlines
1 parent 12f5ca6 commit b75b0e6

File tree

2 files changed

+43
-20
lines changed

2 files changed

+43
-20
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,9 @@ def draw(self, renderer):
481481
# Draw panes first
482482
for axis in self._axis_map.values():
483483
axis.draw_pane(renderer)
484+
# Then gridlines
485+
for axis in self._axis_map.values():
486+
axis.draw_grid(renderer)
484487
# Then axes
485488
for axis in self._axis_map.values():
486489
axis.draw(renderer)

lib/mpl_toolkits/mplot3d/axis3d.py

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -437,26 +437,6 @@ def draw(self, renderer):
437437
self.offsetText.set_ha(align)
438438
self.offsetText.draw(renderer)
439439

440-
if self.axes._draw_grid and len(ticks):
441-
# Grid points where the planes meet
442-
xyz0 = np.tile(minmax, (len(ticks), 1))
443-
xyz0[:, index] = [tick.get_loc() for tick in ticks]
444-
445-
# Grid lines go from the end of one plane through the plane
446-
# intersection (at xyz0) to the end of the other plane. The first
447-
# point (0) differs along dimension index-2 and the last (2) along
448-
# dimension index-1.
449-
lines = np.stack([xyz0, xyz0, xyz0], axis=1)
450-
lines[:, 0, index - 2] = maxmin[index - 2]
451-
lines[:, 2, index - 1] = maxmin[index - 1]
452-
self.gridlines.set_segments(lines)
453-
gridinfo = info['grid']
454-
self.gridlines.set_color(gridinfo['color'])
455-
self.gridlines.set_linewidth(gridinfo['linewidth'])
456-
self.gridlines.set_linestyle(gridinfo['linestyle'])
457-
self.gridlines.do_3d_projection()
458-
self.gridlines.draw(renderer)
459-
460440
# Draw ticks:
461441
tickdir = self._get_tickdir()
462442
tickdelta = deltas[tickdir] if highs[tickdir] else -deltas[tickdir]
@@ -494,6 +474,46 @@ def draw(self, renderer):
494474
renderer.close_group('axis3d')
495475
self.stale = False
496476

477+
@artist.allow_rasterization
478+
def draw_grid(self, renderer):
479+
if not self.axes._draw_grid:
480+
return
481+
482+
self.label._transform = self.axes.transData
483+
renderer.open_group("grid3d", gid=self.get_gid())
484+
485+
ticks = self._update_ticks()
486+
if len(ticks):
487+
# Get general axis information:
488+
info = self._axinfo
489+
index = info["i"]
490+
491+
mins, maxs, tc, highs = self._get_coord_info()
492+
493+
minmax = np.where(highs, maxs, mins)
494+
maxmin = np.where(~highs, maxs, mins)
495+
496+
# Grid points where the planes meet
497+
xyz0 = np.tile(minmax, (len(ticks), 1))
498+
xyz0[:, index] = [tick.get_loc() for tick in ticks]
499+
500+
# Grid lines go from the end of one plane through the plane
501+
# intersection (at xyz0) to the end of the other plane. The first
502+
# point (0) differs along dimension index-2 and the last (2) along
503+
# dimension index-1.
504+
lines = np.stack([xyz0, xyz0, xyz0], axis=1)
505+
lines[:, 0, index - 2] = maxmin[index - 2]
506+
lines[:, 2, index - 1] = maxmin[index - 1]
507+
self.gridlines.set_segments(lines)
508+
gridinfo = info['grid']
509+
self.gridlines.set_color(gridinfo['color'])
510+
self.gridlines.set_linewidth(gridinfo['linewidth'])
511+
self.gridlines.set_linestyle(gridinfo['linestyle'])
512+
self.gridlines.do_3d_projection()
513+
self.gridlines.draw(renderer)
514+
515+
renderer.close_group('grid3d')
516+
497517
# TODO: Get this to work (more) properly when mplot3d supports the
498518
# transforms framework.
499519
def get_tightbbox(self, renderer=None, *, for_layout_only=False):

0 commit comments

Comments
 (0)
0