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

Skip to content

Commit aef1db1

Browse files
committed
FIX: add autopos to suplabels
1 parent 7796c24 commit aef1db1

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,21 +291,21 @@ def _make_margin_suptitles(fig, renderer, *, w_pad=0, h_pad=0):
291291

292292
if fig._suptitle is not None and fig._suptitle.get_in_layout():
293293
p = fig._suptitle.get_position()
294-
if p == (0.5, 0.98): # default position, so assume we can move
294+
if fig._suptitle._autopos: # default position, so assume we can move
295295
fig._suptitle.set_position((p[0], 1 - h_pad_local))
296296
bbox = inv_trans_fig(fig._suptitle.get_tightbbox(renderer))
297297
fig._layoutgrid.edit_margin_min('top', bbox.height + 2 * h_pad)
298298

299299
if fig._supxlabel is not None and fig._supxlabel.get_in_layout():
300300
p = fig._supxlabel.get_position()
301-
if p == (0.5, 0.01):
301+
if fig._supxlabel._autopos:
302302
fig._supxlabel.set_position((p[0], h_pad_local))
303303
bbox = inv_trans_fig(fig._supxlabel.get_tightbbox(renderer))
304304
fig._layoutgrid.edit_margin_min('bottom', bbox.height + 2 * h_pad)
305305

306306
if fig._supylabel is not None and fig._supxlabel.get_in_layout():
307307
p = fig._supylabel.get_position()
308-
if p == (0.02, 0.5,):
308+
if fig._supxlabel._autopos:
309309
fig._supylabel.set_position((w_pad_local, p[1]))
310310
bbox = inv_trans_fig(fig._supylabel.get_tightbbox(renderer))
311311
fig._layoutgrid.edit_margin_min('left', bbox.width + 2 * w_pad)

lib/matplotlib/figure.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,16 @@ def _suplabels(self, t, info, **kwargs):
372372
manual_position = ('x' in kwargs or 'y' in kwargs)
373373
suplab = getattr(self, info['name'])
374374

375-
x = kwargs.pop('x', info['x0'])
376-
y = kwargs.pop('y', info['y0'])
375+
x = kwargs.pop('x', None)
376+
y = kwargs.pop('y', None)
377+
if x is None and y is None:
378+
autopos = True
379+
else:
380+
autopos = False
381+
if x is None:
382+
x = info['x0']
383+
if y is None:
384+
y = info['y0']
377385

378386
if 'horizontalalignment' not in kwargs and 'ha' not in kwargs:
379387
kwargs['horizontalalignment'] = info['ha']
@@ -396,6 +404,7 @@ def _suplabels(self, t, info, **kwargs):
396404
sup.remove()
397405
else:
398406
suplab = sup
407+
suplab._autopos = autopos
399408
setattr(self, info['name'], suplab)
400409
self.stale = True
401410
return suplab

0 commit comments

Comments
 (0)