Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e899c4e

Browse filesBrowse files
committed
Include outward ticks in bounding box
1 parent e789a70 commit e899c4e
Copy full SHA for e899c4e

File tree

Expand file treeCollapse file tree

2 files changed

+26
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+26
-8
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,11 @@ def get_window_extent(self, *args, **kwargs):
567567
get the axes bounding box in display space; *args* and
568568
*kwargs* are empty
569569
"""
570-
return self.bbox
570+
bbox = self.bbox
571+
x_pad = self.xaxis.get_tick_padding()
572+
y_pad = self.yaxis.get_tick_padding()
573+
return mtransforms.Bbox([[bbox.x0 - x_pad, bbox.y0 - y_pad],
574+
[bbox.x1 + x_pad, bbox.y0 + y_pad]])
571575

572576
def _init_axis(self):
573577
"move this out of __init__ because non-separable axes don't use it"

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+21-7Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ def apply_tickdir(self, tickdir):
169169
"""
170170
pass
171171

172+
def get_tickdir(self):
173+
return self._tickdir
174+
175+
def get_tick_padding(self):
176+
"""
177+
Get the length of the tick outside of the axes.
178+
"""
179+
tickdir = self._tickdir
180+
if tickdir == 'in':
181+
return 0.0
182+
elif tickdir == 'inout':
183+
return self._size / 2
184+
elif tickdir == 'out':
185+
return self._size
186+
172187
def get_children(self):
173188
children = [self.tick1line, self.tick2line,
174189
self.gridline, self.label1, self.label2]
@@ -349,13 +364,11 @@ def apply_tickdir(self, tickdir):
349364

350365
if self._tickdir == 'in':
351366
self._tickmarkers = (mlines.TICKUP, mlines.TICKDOWN)
352-
self._pad = self._base_pad
353367
elif self._tickdir == 'inout':
354368
self._tickmarkers = ('|', '|')
355-
self._pad = self._base_pad + self._size / 2.
356369
else:
357370
self._tickmarkers = (mlines.TICKDOWN, mlines.TICKUP)
358-
self._pad = self._base_pad + self._size
371+
self._pad = self._base_pad + self.get_tick_padding()
359372
self.stale = True
360373

361374
def _get_text1(self):
@@ -485,13 +498,11 @@ def apply_tickdir(self, tickdir):
485498

486499
if self._tickdir == 'in':
487500
self._tickmarkers = (mlines.TICKRIGHT, mlines.TICKLEFT)
488-
self._pad = self._base_pad
489501
elif self._tickdir == 'inout':
490502
self._tickmarkers = ('_', '_')
491-
self._pad = self._base_pad + self._size / 2.
492503
else:
493504
self._tickmarkers = (mlines.TICKLEFT, mlines.TICKRIGHT)
494-
self._pad = self._base_pad + self._size
505+
self._pad = self._base_pad + self.get_tick_padding()
495506
self.stale = True
496507

497508
# how far from the y axis line the right of the ticklabel are
@@ -1067,7 +1078,7 @@ def _get_tick_bboxes(self, ticks, renderer):
10671078
def get_tightbbox(self, renderer):
10681079
"""
10691080
Return a bounding box that encloses the axis. It only accounts
1070-
tick labels, axis label, and offsetText.
1081+
tick labels, axis label, offsetText and ticks themselves.
10711082
"""
10721083
if not self.get_visible():
10731084
return
@@ -1097,6 +1108,9 @@ def get_tightbbox(self, renderer):
10971108
else:
10981109
return None
10991110

1111+
def get_tick_padding(self):
1112+
return self.majorTicks[0].get_tick_padding()
1113+
11001114
@allow_rasterization
11011115
def draw(self, renderer, *args, **kwargs):
11021116
'Draw the axis lines, grid lines, tick lines and labels'

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.