Skip to content

Commit

Permalink
Change api of Axes.get_tightbbox and add an optional keyword paramete…
Browse files Browse the repository at this point in the history
…r *call_axes_locator*
  • Loading branch information
leejjoon committed Aug 18, 2011
1 parent 62d7d60 commit fcebc23
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
@@ -1,3 +1,6 @@
2011-08-18 Change api of Axes.get_tightbbox and add an optional
keyword parameter *call_axes_locator*. - JJL

2011-07-15 The set of markers available in the plot() and scatter()
commands has been unified. In general, this gives more
options to both than were previously available, however,
Expand Down
13 changes: 9 additions & 4 deletions lib/matplotlib/axes.py
Expand Up @@ -5770,7 +5770,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
marker_obj.get_transform())
if not marker_obj.is_filled():
edgecolors = 'face'

collection = mcoll.PathCollection(
(path,), scales,
facecolors = colors,
Expand Down Expand Up @@ -8242,11 +8242,16 @@ def matshow(self, Z, **kwargs):
integer=True))
return im


def get_tightbbox(self, renderer):
def get_tightbbox(self, renderer, call_axes_locator=True):
"""
return the tight bounding box of the axes.
The dimension of the Bbox in canvas coordinate.
If call_axes_locator is False, it does not call the
_axes_locator attribute, which is necessary to get the correct
bounding box. call_axes_locator==False can be used if the
caller is only intereted in the relative size of the tightbbox
compared to the axes bbox.
"""

artists = []
Expand All @@ -8256,7 +8261,7 @@ def get_tightbbox(self, renderer):
return None

locator = self.get_axes_locator()
if locator:
if locator and call_axes_locator:
pos = locator(self, renderer)
self.apply_aspect(pos)
else:
Expand Down
7 changes: 3 additions & 4 deletions lib/mpl_toolkits/axes_grid1/axes_size.py
Expand Up @@ -270,22 +270,21 @@ def _get_top(tight_bbox, axes_bbox):
top=_get_top)

del _get_left, _get_right, _get_bottom, _get_top

def __init__(self, ax, direction):
if isinstance(ax, Axes):
self._ax_list = [ax]
else:
self._ax_list = ax

try:
self._get_func = self._get_func_map[direction]
except KeyError:
print "direction must be one of left, right, bottom, top"
raise

def __call__(self, renderer):
vl = [self._get_func(ax.get_tightbbox(renderer),
vl = [self._get_func(ax.get_tightbbox(renderer, False),
ax.bbox) for ax in self._ax_list]
return max(vl)


19 changes: 10 additions & 9 deletions lib/mpl_toolkits/axes_grid1/parasite_axes.py
Expand Up @@ -208,7 +208,7 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
parasite_axes_class = parasite_axes_class_factory(axes_class)
else:
parasite_axes_class = axes_class

new_class = _parasite_axes_auxtrans_classes.get(parasite_axes_class)
if new_class is None:
import new
Expand Down Expand Up @@ -319,7 +319,7 @@ def twinx(self, axes_class=None):
axes_class = self._get_base_axes()

parasite_axes_class = parasite_axes_class_factory(axes_class)

ax2 = parasite_axes_class(self, sharex=self, frameon=False)
self.parasites.append(ax2)

Expand Down Expand Up @@ -353,7 +353,7 @@ def twiny(self, axes_class=None):
axes_class = self._get_base_axes()

parasite_axes_class = parasite_axes_class_factory(axes_class)

ax2 = parasite_axes_class(self, sharey=self, frameon=False)
self.parasites.append(ax2)

Expand Down Expand Up @@ -386,7 +386,7 @@ def twin(self, aux_trans=None, axes_class=None):
axes_class = self._get_base_axes()

parasite_axes_auxtrans_class = parasite_axes_auxtrans_class_factory(axes_class)

if aux_trans is None:
ax2 = parasite_axes_auxtrans_class(self, mtransforms.IdentityTransform(),
viewlim_mode="equal",
Expand Down Expand Up @@ -436,23 +436,24 @@ def twin(self, aux_trans=None, axes_class=None):

return ax2

def get_tightbbox(self, renderer):
def get_tightbbox(self, renderer, call_axes_locator=True):

bbs = [ax.get_tightbbox(renderer) for ax in self.parasites]
bbs = [ax.get_tightbbox(renderer, call_axes_locator) \
for ax in self.parasites]
get_tightbbox = self._get_base_axes_attr("get_tightbbox")
bbs.append(get_tightbbox(self, renderer))
bbs.append(get_tightbbox(self, renderer, call_axes_locator))

_bbox = Bbox.union([b for b in bbs if b.width!=0 or b.height!=0])

return _bbox



_host_axes_classes = {}
def host_axes_class_factory(axes_class=None):
if axes_class is None:
axes_class = Axes

new_class = _host_axes_classes.get(axes_class)
if new_class is None:
import new
Expand Down
18 changes: 9 additions & 9 deletions lib/mpl_toolkits/axisartist/axislines.py
Expand Up @@ -378,7 +378,7 @@ def get_tick_iterators(self, axes):
angle_normal, angle_tangent = 90, 0
else:
angle_normal, angle_tangent = 0, 90

#angle = 90 - 90 * self.nth_coord

major = self.axis.major
Expand Down Expand Up @@ -459,7 +459,7 @@ def new_fixed_axis(self, loc,
offset=None,
axes=None,
):

if axes is None:
warnings.warn("'new_fixed_axis' explicitly requires the axes keyword.")
axes = self.axes
Expand Down Expand Up @@ -733,9 +733,9 @@ def draw(self, renderer, inframe=False):
self.artists = orig_artists


def get_tightbbox(self, renderer):
def get_tightbbox(self, renderer, call_axes_locator=True):

bb0 = super(Axes, self).get_tightbbox(renderer)
bb0 = super(Axes, self).get_tightbbox(renderer, call_axes_locator)

if not self._axisline_on:
return bb0
Expand Down Expand Up @@ -777,13 +777,13 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False,

if not swap_axis:
return

if (x1o > x2o and x1 < x2) or (x1o < x2o and x1 > x2):
self.axis["right"], self.axis["left"] = self.axis["left"], self.axis["right"]
self.axis["right"], self.axis["left"] = self.axis["left"], self.axis["right"]

self.axis["left"].set_axis_direction("left")
self.axis["right"].set_axis_direction("right")


def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
swap_axis=True, **kw):
Expand All @@ -794,11 +794,11 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
y1, y2 = self.get_ylim()

if y1o > y2o and y1 < y2 or (y1o < y2o and y1 > y2):
self.axis["top"], self.axis["bottom"] = self.axis["bottom"], self.axis["top"]
self.axis["top"], self.axis["bottom"] = self.axis["bottom"], self.axis["top"]

self.axis["top"].set_axis_direction("top")
self.axis["bottom"].set_axis_direction("bottom")



Subplot = maxes.subplot_class_factory(Axes)
Expand Down

0 comments on commit fcebc23

Please sign in to comment.