Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7108a60

Browse filesBrowse files
committed
FIX: move titles up if overlap axes
1 parent 0f05cf4 commit 7108a60
Copy full SHA for 7108a60

File tree

Expand file treeCollapse file tree

1 file changed

+29
-16
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-16
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+29-16Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,34 +2470,47 @@ def _update_title_position(self, renderer):
24702470
x, y = title.get_position()
24712471
if not np.isclose(y, 1.0):
24722472
self._autotitlepos = False
2473-
_log.debug('not adjusting title pos because title was'
2473+
_log.debug('not adjusting title pos because a title was'
24742474
' already placed manually: %f', y)
24752475
return
24762476
self._autotitlepos = True
24772477

2478+
ymax = -10
24782479
for title in titles:
24792480
x, y0 = title.get_position()
2480-
y = 1.0
2481+
y = y0
2482+
bt = title.get_window_extent(renderer)
24812483
# need to check all our twins too...
24822484
axs = self._twinned_axes.get_siblings(self)
24832485

24842486
for ax in axs:
24852487
try:
2488+
bb = ax.get_window_extent(renderer)
24862489
if (ax.xaxis.get_label_position() == 'top'
24872490
or ax.xaxis.get_ticks_position() == 'top'):
2488-
bb = ax.xaxis.get_tightbbox(renderer)
2489-
top = bb.ymax
2490-
# we don't need to pad because the padding is already
2491-
# in __init__: titleOffsetTrans
2492-
yn = self.transAxes.inverted().transform((0., top))[1]
2493-
y = max(y, yn)
2491+
bb = mtransforms.Bbox.union([bb,
2492+
ax.xaxis.get_tightbbox(renderer)])
2493+
# need to do twice to get right for manual resizing
2494+
dy = bt.ymin - bb.ymax
2495+
if dy < 0:
2496+
y = self.transAxes.inverted().transform(
2497+
(0., bb.ymax - dy))[1]
2498+
title.set_position((x, y))
2499+
#bt = title.get_window_extent(renderer)
24942500
except AttributeError:
2495-
pass
2501+
y = 1
2502+
ymax = np.max((y, ymax))
2503+
for title in titles:
2504+
# now line up all the titles at the highest baseline.
2505+
x, y0 = title.get_position()
2506+
title.set_position((x, ymax))
2507+
2508+
24962509

2497-
title.set_position((x, y))
24982510

2499-
# Drawing
25002511

2512+
2513+
# Drawing
25012514
@allow_rasterization
25022515
def draw(self, renderer=None, inframe=False):
25032516
"""Draw everything (plot lines, axes, labels)"""
@@ -4133,19 +4146,19 @@ def get_tightbbox(self, renderer, call_axes_locator=True):
41334146
if bb_xaxis:
41344147
bb.append(bb_xaxis)
41354148

4136-
self._update_title_position(renderer)
4137-
bb.append(self.get_window_extent(renderer))
4149+
bb_yaxis = self.yaxis.get_tightbbox(renderer)
4150+
if bb_yaxis:
4151+
bb.append(bb_yaxis)
41384152

4153+
self._update_title_position(renderer)
41394154
if self.title.get_visible():
41404155
bb.append(self.title.get_window_extent(renderer))
41414156
if self._left_title.get_visible():
41424157
bb.append(self._left_title.get_window_extent(renderer))
41434158
if self._right_title.get_visible():
41444159
bb.append(self._right_title.get_window_extent(renderer))
41454160

4146-
bb_yaxis = self.yaxis.get_tightbbox(renderer)
4147-
if bb_yaxis:
4148-
bb.append(bb_yaxis)
4161+
bb.append(self.get_window_extent(renderer))
41494162

41504163
for child in self.get_children():
41514164
if isinstance(child, OffsetBox) and child.get_visible():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.