Skip to content

Commit fcebc23

Browse files
committed
Change api of Axes.get_tightbbox and add an optional keyword parameter *call_axes_locator*
1 parent 62d7d60 commit fcebc23

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2011-08-18 Change api of Axes.get_tightbbox and add an optional
2+
keyword parameter *call_axes_locator*. - JJL
3+
14
2011-07-15 The set of markers available in the plot() and scatter()
25
commands has been unified. In general, this gives more
36
options to both than were previously available, however,

lib/matplotlib/axes.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5770,7 +5770,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None,
57705770
marker_obj.get_transform())
57715771
if not marker_obj.is_filled():
57725772
edgecolors = 'face'
5773-
5773+
57745774
collection = mcoll.PathCollection(
57755775
(path,), scales,
57765776
facecolors = colors,
@@ -8242,11 +8242,16 @@ def matshow(self, Z, **kwargs):
82428242
integer=True))
82438243
return im
82448244

8245-
8246-
def get_tightbbox(self, renderer):
8245+
def get_tightbbox(self, renderer, call_axes_locator=True):
82478246
"""
82488247
return the tight bounding box of the axes.
82498248
The dimension of the Bbox in canvas coordinate.
8249+
8250+
If call_axes_locator is False, it does not call the
8251+
_axes_locator attribute, which is necessary to get the correct
8252+
bounding box. call_axes_locator==False can be used if the
8253+
caller is only intereted in the relative size of the tightbbox
8254+
compared to the axes bbox.
82508255
"""
82518256

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

82588263
locator = self.get_axes_locator()
8259-
if locator:
8264+
if locator and call_axes_locator:
82608265
pos = locator(self, renderer)
82618266
self.apply_aspect(pos)
82628267
else:

lib/mpl_toolkits/axes_grid1/axes_size.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,22 +270,21 @@ def _get_top(tight_bbox, axes_bbox):
270270
top=_get_top)
271271

272272
del _get_left, _get_right, _get_bottom, _get_top
273-
273+
274274
def __init__(self, ax, direction):
275275
if isinstance(ax, Axes):
276276
self._ax_list = [ax]
277277
else:
278278
self._ax_list = ax
279-
279+
280280
try:
281281
self._get_func = self._get_func_map[direction]
282282
except KeyError:
283283
print "direction must be one of left, right, bottom, top"
284284
raise
285285

286286
def __call__(self, renderer):
287-
vl = [self._get_func(ax.get_tightbbox(renderer),
287+
vl = [self._get_func(ax.get_tightbbox(renderer, False),
288288
ax.bbox) for ax in self._ax_list]
289289
return max(vl)
290-
291290

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def parasite_axes_auxtrans_class_factory(axes_class=None):
208208
parasite_axes_class = parasite_axes_class_factory(axes_class)
209209
else:
210210
parasite_axes_class = axes_class
211-
211+
212212
new_class = _parasite_axes_auxtrans_classes.get(parasite_axes_class)
213213
if new_class is None:
214214
import new
@@ -319,7 +319,7 @@ def twinx(self, axes_class=None):
319319
axes_class = self._get_base_axes()
320320

321321
parasite_axes_class = parasite_axes_class_factory(axes_class)
322-
322+
323323
ax2 = parasite_axes_class(self, sharex=self, frameon=False)
324324
self.parasites.append(ax2)
325325

@@ -353,7 +353,7 @@ def twiny(self, axes_class=None):
353353
axes_class = self._get_base_axes()
354354

355355
parasite_axes_class = parasite_axes_class_factory(axes_class)
356-
356+
357357
ax2 = parasite_axes_class(self, sharey=self, frameon=False)
358358
self.parasites.append(ax2)
359359

@@ -386,7 +386,7 @@ def twin(self, aux_trans=None, axes_class=None):
386386
axes_class = self._get_base_axes()
387387

388388
parasite_axes_auxtrans_class = parasite_axes_auxtrans_class_factory(axes_class)
389-
389+
390390
if aux_trans is None:
391391
ax2 = parasite_axes_auxtrans_class(self, mtransforms.IdentityTransform(),
392392
viewlim_mode="equal",
@@ -436,23 +436,24 @@ def twin(self, aux_trans=None, axes_class=None):
436436

437437
return ax2
438438

439-
def get_tightbbox(self, renderer):
439+
def get_tightbbox(self, renderer, call_axes_locator=True):
440440

441-
bbs = [ax.get_tightbbox(renderer) for ax in self.parasites]
441+
bbs = [ax.get_tightbbox(renderer, call_axes_locator) \
442+
for ax in self.parasites]
442443
get_tightbbox = self._get_base_axes_attr("get_tightbbox")
443-
bbs.append(get_tightbbox(self, renderer))
444+
bbs.append(get_tightbbox(self, renderer, call_axes_locator))
444445

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

447448
return _bbox
448-
449+
449450

450451

451452
_host_axes_classes = {}
452453
def host_axes_class_factory(axes_class=None):
453454
if axes_class is None:
454455
axes_class = Axes
455-
456+
456457
new_class = _host_axes_classes.get(axes_class)
457458
if new_class is None:
458459
import new

lib/mpl_toolkits/axisartist/axislines.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ def get_tick_iterators(self, axes):
378378
angle_normal, angle_tangent = 90, 0
379379
else:
380380
angle_normal, angle_tangent = 0, 90
381-
381+
382382
#angle = 90 - 90 * self.nth_coord
383383

384384
major = self.axis.major
@@ -459,7 +459,7 @@ def new_fixed_axis(self, loc,
459459
offset=None,
460460
axes=None,
461461
):
462-
462+
463463
if axes is None:
464464
warnings.warn("'new_fixed_axis' explicitly requires the axes keyword.")
465465
axes = self.axes
@@ -733,9 +733,9 @@ def draw(self, renderer, inframe=False):
733733
self.artists = orig_artists
734734

735735

736-
def get_tightbbox(self, renderer):
736+
def get_tightbbox(self, renderer, call_axes_locator=True):
737737

738-
bb0 = super(Axes, self).get_tightbbox(renderer)
738+
bb0 = super(Axes, self).get_tightbbox(renderer, call_axes_locator)
739739

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

778778
if not swap_axis:
779779
return
780-
780+
781781
if (x1o > x2o and x1 < x2) or (x1o < x2o and x1 > x2):
782-
self.axis["right"], self.axis["left"] = self.axis["left"], self.axis["right"]
782+
self.axis["right"], self.axis["left"] = self.axis["left"], self.axis["right"]
783783

784784
self.axis["left"].set_axis_direction("left")
785785
self.axis["right"].set_axis_direction("right")
786-
786+
787787

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

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

799799
self.axis["top"].set_axis_direction("top")
800800
self.axis["bottom"].set_axis_direction("bottom")
801-
801+
802802

803803

804804
Subplot = maxes.subplot_class_factory(Axes)

0 commit comments

Comments
 (0)