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 08fc864

Browse filesBrowse files
committed
Merge pull request #5683 from mdboom/tight-ticks
Include outward ticks in bounding box
2 parents 9f6bb90 + 0a4b52e commit 08fc864
Copy full SHA for 08fc864

File tree

Expand file treeCollapse file tree

6 files changed

+863
-7
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+863
-7
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.y1 + 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
+26-6Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,20 @@ 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+
padding = {
180+
'in': 0.0,
181+
'inout': 0.5,
182+
'out': 1.0
183+
}
184+
return self._size * padding[self._tickdir]
185+
172186
def get_children(self):
173187
children = [self.tick1line, self.tick2line,
174188
self.gridline, self.label1, self.label2]
@@ -349,13 +363,11 @@ def apply_tickdir(self, tickdir):
349363

350364
if self._tickdir == 'in':
351365
self._tickmarkers = (mlines.TICKUP, mlines.TICKDOWN)
352-
self._pad = self._base_pad
353366
elif self._tickdir == 'inout':
354367
self._tickmarkers = ('|', '|')
355-
self._pad = self._base_pad + self._size / 2.
356368
else:
357369
self._tickmarkers = (mlines.TICKDOWN, mlines.TICKUP)
358-
self._pad = self._base_pad + self._size
370+
self._pad = self._base_pad + self.get_tick_padding()
359371
self.stale = True
360372

361373
def _get_text1(self):
@@ -485,13 +497,11 @@ def apply_tickdir(self, tickdir):
485497

486498
if self._tickdir == 'in':
487499
self._tickmarkers = (mlines.TICKRIGHT, mlines.TICKLEFT)
488-
self._pad = self._base_pad
489500
elif self._tickdir == 'inout':
490501
self._tickmarkers = ('_', '_')
491-
self._pad = self._base_pad + self._size / 2.
492502
else:
493503
self._tickmarkers = (mlines.TICKLEFT, mlines.TICKRIGHT)
494-
self._pad = self._base_pad + self._size
504+
self._pad = self._base_pad + self.get_tick_padding()
495505
self.stale = True
496506

497507
# how far from the y axis line the right of the ticklabel are
@@ -1097,6 +1107,16 @@ def get_tightbbox(self, renderer):
10971107
else:
10981108
return None
10991109

1110+
def get_tick_padding(self):
1111+
values = []
1112+
if len(self.majorTicks):
1113+
values.append(self.majorTicks[0].get_tick_padding())
1114+
if len(self.minorTicks):
1115+
values.append(self.minorTicks[0].get_tick_padding())
1116+
if len(values):
1117+
return max(values)
1118+
return 0.0
1119+
11001120
@allow_rasterization
11011121
def draw(self, renderer, *args, **kwargs):
11021122
'Draw the axis lines, grid lines, tick lines and labels'
Binary file not shown.
Loading

0 commit comments

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