8000 FIX: check if axes is off page before repositioning title by jklymak · Pull Request #18288 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: check if axes is off page before repositioning title #18288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2632,7 +2632,6 @@ def _update_title_position(self, renderer):
Update the title position based on the bounding box enclosing
all the ticklabels and x-axis spine and xlabel...
"""

if self._autotitlepos is not None and not self._autotitlepos:
_log.debug('title position was updated manually, not adjusting')
return
Expand All @@ -2655,7 +2654,7 @@ def _update_title_position(self, renderer):
else:
ax.apply_aspect()
axs = axs + [ax]
top = 0
top = -np.Inf
for ax in axs:
if (ax.xaxis.get_ticks_position() in ['top', 'unknown']
or ax.xaxis.get_label_position() == 'top'):
Expand All @@ -2664,6 +2663,11 @@ def _update_title_position(self, renderer):
bb = ax.get_window_extent(renderer)
if bb is not None:
top = max(top, bb.ymax)
if top < 0:
# the top of axes is not even on the figure, so don't try and
# automatically place it.
_log.debug('top of axes not in the figure, so title not moved')
return
if title.get_window_extent(renderer).ymin < top:
_, y = self.transAxes.inverted().transform((0, top))
title.set_position((x, y))
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5533,6 +5533,19 @@ def test_title_xticks_top_both():
assert ax.title.get_position()[1] > 1.04


def test_title_no_move_off_page():
# If an axes is off the figure (ie. if it is cropped during a save)
# make sure that the automatic title repositioning does not get done.
mpl.rcParams['axes.titley'] = None
fig = plt.figure()
ax = fig.add_axes([0.1, -0.5, 0.8, 0.2])
ax.tick_params(axis="x",
bottom=True, top=True, labelbottom=True, labeltop=True)
tt = ax.set_title('Boo')
fig.canvas.draw()
assert tt.get_position()[1] == 1.0


def test_offset_label_color():
# Tests issue 6440
fig = plt.figure()
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_pickle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from io import BytesIO
import pickle
import platform
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to make flake8 happy - not part of this PR, but flake8 now seems to check all files, not just modified.


import numpy as np
import pytest
Expand Down
0