Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dc81e88

Browse files
committed
works?
1 parent 1bed724 commit dc81e88

File tree

5 files changed

+44
-22
lines changed

5 files changed

+44
-22
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,12 +268,9 @@ def _make_layout_margins(ax, renderer, h_pad, w_pad):
268268
"""
269269
fig = ax.figure
270270
invTransFig = fig.transFigure.inverted().transform_bbox
271-
print('ax', ax, invTransFig)
272271
pos = ax.get_position(original=True)
273272
tightbbox = ax.get_tightbbox(renderer=renderer)
274-
print(pos, tightbbox)
275273
bbox = invTransFig(tightbbox)
276-
print('bbox', bbox)
277274
# this can go wrong:
278275
if not np.isfinite(bbox.y0 + bbox.x0 + bbox.y1 + bbox.x1):
279276
# just abort, this is likely a bad set of co-ordinates that

lib/matplotlib/axes/_base.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,7 +4210,6 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
42104210
bb_xaxis = self.xaxis.get_tightbbox(renderer)
42114211
if bb_xaxis:
42124212
bb.append(bb_xaxis)
4213-
42144213
self._update_title_position(renderer)
42154214
bb.append(self.get_window_extent(renderer))
42164215

@@ -4230,9 +4229,11 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
42304229
bbox_artists = self.get_default_bbox_extra_artists()
42314230

42324231
for a in bbox_artists:
4233-
bbox = a.get_tightbbox(renderer)
4234-
if bbox is not None and (bbox.width != 0 or bbox.height != 0):
4235-
bb.append(bbox)
4232+
bbox = a.get_tightbbox(renderer, )
4233+
if (bbox is not None and
4234+
(bbox.width != 0 or bbox.height != 0) and
4235+
np.isfinite(bbox.x0 + bbox.x1 + bbox.y0 + bbox.y1)):
4236+
bb.append(bbox)
42364237

42374238
_bbox = mtransforms.Bbox.union(
42384239
[b for b in bb if b.width != 0 or b.height != 0])

lib/matplotlib/axes/_secondary_axes.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
)
2222

2323

24-
def _make_secondary_locator(rect, trans, parent):
24+
def _make_secondary_locator(rect, parent):
2525
"""
2626
Helper function to locate the secondary axes.
2727
@@ -37,17 +37,18 @@ def _make_secondary_locator(rect, trans, parent):
3737
*parent*.
3838
"""
3939
_rect = mtransforms.Bbox.from_bounds(*rect)
40-
_trans = trans
4140
_parent = parent
41+
_trans = _parent.transAxes
4242

43-
def inset_locator(ax, renderer):
43+
44+
def secondary_locator(ax, renderer):
4445
bbox = _rect
4546
bb = mtransforms.TransformedBbox(bbox, _trans)
4647
tr = _parent.figure.transFigure.inverted()
4748
bb = mtransforms.TransformedBbox(bb, tr)
4849
return bb
4950

50-
return inset_locator
51+
return secondary_locator
5152

5253

5354
def _parse_conversion(name, otherargs):
@@ -174,17 +175,19 @@ def set_location(self, location):
174175
else:
175176
bounds = [self._pos, 0, 1e-10, 1]
176177

177-
transform = self._parent.transAxes
178-
secondary_locator = _make_secondary_locator(bounds,
179-
transform, self._parent)
180-
bb = secondary_locator(None, None)
178+
secondary_locator = _make_secondary_locator(bounds, self._parent)
181179

182180
# this locator lets the axes move in the parent axes coordinates.
183181
# so it never needs to know where the parent is explicitly in
184182
# figure co-ordinates.
185183
# it gets called in `ax.apply_aspect() (of all places)
186184
self.set_axes_locator(secondary_locator)
187185

186+
def apply_aspect(self, position=None):
187+
self._set_lims()
188+
super().apply_aspect(position)
189+
190+
188191
def set_ticks(self, ticks, minor=False):
189192
"""
190193
Set the x ticks with list of *ticks*
@@ -264,7 +267,7 @@ def set_conversion(self, conversion, otherargs=None):
264267
self._convert = conversion
265268
# this will track log/non log so long as the user sets...
266269
set_scale(self._parent.get_xscale())
267-
270+
268271
def draw(self, renderer=None, inframe=False):
269272
"""
270273
Draw the secondary axes.
@@ -276,6 +279,11 @@ def draw(self, renderer=None, inframe=False):
276279
277280
"""
278281

282+
self._set_lims()
283+
super().draw(renderer=renderer, inframe=inframe)
284+
285+
def _set_lims(self):
286+
279287
if self._orientation == 'x':
280288
lims = self._parent.get_xlim()
281289
set_lim = self.set_xlim
@@ -288,9 +296,7 @@ def draw(self, renderer=None, inframe=False):
288296
if neworder != order:
289297
# flip because the transform will take care of the flipping..
290298
lims = lims[::-1]
291-
292299
set_lim(lims)
293-
super().draw(renderer=renderer, inframe=inframe)
294300

295301
def get_tightbbox(self, renderer, call_axes_locator=True):
296302
"""
@@ -309,12 +315,14 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
309315
if not self.get_visible():
310316
return None
311317

318+
self._set_lims()
312319
locator = self.get_axes_locator()
313320
if locator and call_axes_locator:
314321
pos = locator(self, renderer)
315322
self.apply_aspect(pos)
316323
else:
317324
self.apply_aspect()
325+
318326
if self._orientation == 'x':
319327
bb_axis = self.xaxis.get_tightbbox(renderer)
320328
else:
@@ -323,10 +331,10 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
323331
bb.append(bb_axis)
324332

325333
bb.append(self.get_window_extent(renderer))
326-
327334
_bbox = mtransforms.Bbox.union(
328335
[b for b in bb if b.width != 0 or b.height != 0])
329336

337+
330338
return _bbox
331339

332340
def set_aspect(self, *args, **kwargs):

lib/matplotlib/axis.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,11 +1155,10 @@ def get_tightbbox(self, renderer):
11551155
if (np.isfinite(bbox.width) and np.isfinite(bbox.height) and
11561156
a.get_visible()):
11571157
bb.append(bbox)
1158-
11591158
bb.extend(ticklabelBoxes)
11601159
bb.extend(ticklabelBoxes2)
1161-
1162-
bb = [b for b in bb if b.width != 0 or b.height != 0]
1160+
bb = [b for b in bb if ((b.width != 0 or b.height != 0) and
1161+
np.isfinite(b.x0 + b.y0 + b.x1 + b.y1))]
11631162
if bb:
11641163
_bbox = mtransforms.Bbox.union(bb)
11651164
return _bbox

lib/matplotlib/figure.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,23 @@ def draw(self, renderer):
16331633
if not artist.get_animated()),
16341634
key=lambda artist: artist.get_zorder())
16351635

1636+
for ax in self.axes:
1637+
locator = ax.get_axes_locator()
1638+
if locator:
1639+
pos = locator(ax, renderer)
1640+
ax.apply_aspect(pos)
1641+
else:
1642+
ax.apply_aspect()
1643+
1644+
for child in ax.get_children():
1645+
if hasattr(child, 'apply_aspect'):
1646+
locator = child.get_axes_locator()
1647+
if locator:
1648+
pos = locator(child, renderer)
1649+
child.apply_aspect(pos)
1650+
else:
1651+
child.apply_aspect()
1652+
16361653
try:
16371654
renderer.open_group('figure')
16381655
if self.get_constrained_layout() and self.axes:

0 commit comments

Comments
 (0)