Skip to content

Commit a84ecf1

Browse files
authored
Merge pull request #23582 from oscargus/axis3ddrawcleanup
Cleanup axis3d.Axis.draw
2 parents 8a495e9 + 38567d2 commit a84ecf1

File tree

1 file changed

+26
-31
lines changed

1 file changed

+26
-31
lines changed

lib/mpl_toolkits/mplot3d/axis3d.py

+26-31
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,6 @@ def draw(self, renderer):
322322
self.line.set_data(pep[0], pep[1])
323323
self.line.draw(renderer)
324324

325-
# Grid points where the planes meet
326-
xyz0 = np.tile(minmax, (len(ticks), 1))
327-
xyz0[:, index] = [tick.get_loc() for tick in ticks]
328-
329325
# Draw labels
330326
# The transAxes transform is used because the Text object
331327
# rotates the text relative to the display coordinate system.
@@ -414,10 +410,7 @@ def draw(self, renderer):
414410
if (centpt[index] > pep[index, outerindex]
415411
and np.count_nonzero(highs) % 2 == 0):
416412
# Usually mean align left, except if it is axis 2
417-
if index == 2:
418-
align = 'right'
419-
else:
420-
align = 'left'
413+
align = 'right' if index == 2 else 'left'
421414
else:
422415
# The TT case
423416
align = 'right'
@@ -427,6 +420,10 @@ def draw(self, renderer):
427420
self.offsetText.draw(renderer)
428421

429422
if self.axes._draw_grid and len(ticks):
423+
# Grid points where the planes meet
424+
xyz0 = np.tile(minmax, (len(ticks), 1))
425+
xyz0[:, index] = [tick.get_loc() for tick in ticks]
426+
430427
# Grid lines go from the end of one plane through the plane
431428
# intersection (at xyz0) to the end of the other plane. The first
432429
# point (0) differs along dimension index-2 and the last (2) along
@@ -435,47 +432,45 @@ def draw(self, renderer):
435432
lines[:, 0, index - 2] = maxmin[index - 2]
436433
lines[:, 2, index - 1] = maxmin[index - 1]
437434
self.gridlines.set_segments(lines)
438-
self.gridlines.set_color(info['grid']['color'])
439-
self.gridlines.set_linewidth(info['grid']['linewidth'])
440-
self.gridlines.set_linestyle(info['grid']['linestyle'])
435+
gridinfo = info['grid']
436+
self.gridlines.set_color(gridinfo['color'])
437+
self.gridlines.set_linewidth(gridinfo['linewidth'])
438+
self.gridlines.set_linestyle(gridinfo['linestyle'])
441439
self.gridlines.do_3d_projection()
442440
self.gridlines.draw(renderer)
443441

444442
# Draw ticks:
445443
tickdir = self._get_tickdir()
446-
tickdelta = deltas[tickdir]
447-
if highs[tickdir]:
448-
ticksign = 1
449-
else:
450-
ticksign = -1
451-
444+
tickdelta = deltas[tickdir] if highs[tickdir] else -deltas[tickdir]
445+
446+
tick_info = info['tick']
447+
tick_out = tick_info['outward_factor'] * tickdelta
448+
tick_in = tick_info['inward_factor'] * tickdelta
449+
tick_lw = tick_info['linewidth']
450+
edgep1_tickdir = edgep1[tickdir]
451+
out_tickdir = edgep1_tickdir + tick_out
452+
in_tickdir = edgep1_tickdir - tick_in
453+
454+
default_label_offset = 8. # A rough estimate
455+
points = deltas_per_point * deltas
452456
for tick in ticks:
453457
# Get tick line positions
454458
pos = edgep1.copy()
455459
pos[index] = tick.get_loc()
456-
pos[tickdir] = (
457-
edgep1[tickdir]
458-
+ info['tick']['outward_factor'] * ticksign * tickdelta)
460+
pos[tickdir] = out_tickdir
459461
x1, y1, z1 = proj3d.proj_transform(*pos, self.axes.M)
460-
pos[tickdir] = (
461-
edgep1[tickdir]
462-
- info['tick']['inward_factor'] * ticksign * tickdelta)
462+
pos[tickdir] = in_tickdir
463463
x2, y2, z2 = proj3d.proj_transform(*pos, self.axes.M)
464464

465465
# Get position of label
466-
default_offset = 8. # A rough estimate
467-
labeldeltas = (
468-
(tick.get_pad() + default_offset) * deltas_per_point * deltas)
466+
labeldeltas = (tick.get_pad() + default_label_offset) * points
469467

470-
axmask = [True, True, True]
471-
axmask[index] = False
472-
pos[tickdir] = edgep1[tickdir]
468+
pos[tickdir] = edgep1_tickdir
473469
pos = move_from_center(pos, centers, labeldeltas, axmask)
474470
lx, ly, lz = proj3d.proj_transform(*pos, self.axes.M)
475471

476472
tick_update_position(tick, (x1, x2), (y1, y2), (lx, ly))
477-
tick.tick1line.set_linewidth(
478-
info['tick']['linewidth'][tick._major])
473+
tick.tick1line.set_linewidth(tick_lw[tick._major])
479474
tick.draw(renderer)
480475

481476
renderer.close_group('axis3d')

0 commit comments

Comments
 (0)