Include outward ticks in bounding box #5683

Merged
merged 5 commits into from Dec 19, 2015
@@ -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]])
@WeatherGod

WeatherGod Dec 16, 2015

Member

Is this going to work for polar axes? I would also double-check that this doesn't utterly bork for axes3d (not that I'd expect it to work great there, just to not crash or something).

@mdboom

mdboom Dec 16, 2015

Owner

polar axes don't have ticks -- but it does appear that this needs to be updated so it's aware of when the ticks are present or not.

It doesn't seem to crash for axes3d, though as you say, it doesn't really do the right thin other than add a bit more space.

def _init_axis(self):
"move this out of __init__ because non-separable axes don't use it"
View
@@ -169,6 +169,20 @@ 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.
+ """
+ padding = {
+ 'in': 0.0,
+ 'inout': 0.5,
+ 'out': 1.0
+ }
+ return self._size * padding[self._tickdir]
+
def get_children(self):
children = [self.tick1line, self.tick2line,
self.gridline, self.label1, self.label2]
@@ -349,13 +363,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):
@@ -485,13 +497,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
@@ -1097,6 +1107,16 @@ def get_tightbbox(self, renderer):
else:
return None
+ def get_tick_padding(self):
+ values = []
+ if len(self.majorTicks):
+ values.append(self.majorTicks[0].get_tick_padding())
+ if len(self.minorTicks):
+ values.append(self.minorTicks[0].get_tick_padding())
+ if len(values):
+ return max(values)
+ return 0.0
+
@allow_rasterization
def draw(self, renderer, *args, **kwargs):
'Draw the axis lines, grid lines, tick lines and labels'
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.