Skip to content

Commit

Permalink
Include outward ticks in bounding box
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Dec 15, 2015
1 parent e789a70 commit 46ae4d9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
6 changes: 5 additions & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,11 @@ def get_window_extent(self, *args, **kwargs):
get the axes bounding box in display space; *args* and
*kwargs* are empty
"""
return self.bbox
bbox = self.bbox
x_pad = self.xaxis.get_tick_padding()
y_pad = self.yaxis.get_tick_padding()
return mtransforms.Bbox([[bbox.x0 - x_pad, bbox.y0 - y_pad],
[bbox.x1 + x_pad, bbox.y1 + y_pad]])

def _init_axis(self):
"move this out of __init__ because non-separable axes don't use it"
Expand Down
28 changes: 21 additions & 7 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,21 @@ def apply_tickdir(self, tickdir):
"""
pass

def get_tickdir(self):
return self._tickdir

def get_tick_padding(self):
"""
Get the length of the tick outside of the axes.
"""
tickdir = self._tickdir
if tickdir == 'in':
return 0.0
elif tickdir == 'inout':
return self._size / 2
elif tickdir == 'out':
return self._size

def get_children(self):
children = [self.tick1line, self.tick2line,
self.gridline, self.label1, self.label2]
Expand Down Expand Up @@ -349,13 +364,11 @@ def apply_tickdir(self, tickdir):

if self._tickdir == 'in':
self._tickmarkers = (mlines.TICKUP, mlines.TICKDOWN)
self._pad = self._base_pad
elif self._tickdir == 'inout':
self._tickmarkers = ('|', '|')
self._pad = self._base_pad + self._size / 2.
else:
self._tickmarkers = (mlines.TICKDOWN, mlines.TICKUP)
self._pad = self._base_pad + self._size
self._pad = self._base_pad + self.get_tick_padding()
self.stale = True

def _get_text1(self):
Expand Down Expand Up @@ -485,13 +498,11 @@ def apply_tickdir(self, tickdir):

if self._tickdir == 'in':
self._tickmarkers = (mlines.TICKRIGHT, mlines.TICKLEFT)
self._pad = self._base_pad
elif self._tickdir == 'inout':
self._tickmarkers = ('_', '_')
self._pad = self._base_pad + self._size / 2.
else:
self._tickmarkers = (mlines.TICKLEFT, mlines.TICKRIGHT)
self._pad = self._base_pad + self._size
self._pad = self._base_pad + self.get_tick_padding()
self.stale = True

# how far from the y axis line the right of the ticklabel are
Expand Down Expand Up @@ -1067,7 +1078,7 @@ def _get_tick_bboxes(self, ticks, renderer):
def get_tightbbox(self, renderer):
"""
Return a bounding box that encloses the axis. It only accounts
tick labels, axis label, and offsetText.
tick labels, axis label, offsetText and ticks themselves.
"""
if not self.get_visible():
return
Expand Down Expand Up @@ -1097,6 +1108,9 @@ def get_tightbbox(self, renderer):
else:
return None

def get_tick_padding(self):
return self.majorTicks[0].get_tick_padding()

@allow_rasterization
def draw(self, renderer, *args, **kwargs):
'Draw the axis lines, grid lines, tick lines and labels'
Expand Down

0 comments on commit 46ae4d9

Please sign in to comment.