Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commit9a9fce5

Browse files
authored
Merge pull request#28300 from rcomer/empty-titles
Faster title alignment
2 parents2834da1 +1dfc773 commit9a9fce5

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

‎lib/matplotlib/axes/_base.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2985,6 +2985,10 @@ def _update_title_position(self, renderer):
29852985

29862986
titles= (self.title,self._left_title,self._right_title)
29872987

2988+
ifnotany(title.get_text()fortitleintitles):
2989+
# If the titles are all empty, there is no need to update their positions.
2990+
return
2991+
29882992
# Need to check all our twins too, aligned axes, and all the children
29892993
# as well.
29902994
axs=set()
@@ -2996,21 +3000,24 @@ def _update_title_position(self, renderer):
29963000
locator=ax.get_axes_locator()
29973001
ax.apply_aspect(locator(self,renderer)iflocatorelseNone)
29983002

3003+
top=-np.inf
3004+
foraxinaxs:
3005+
bb=None
3006+
xticklabel_top=any(tick.label2.get_visible()fortickin
3007+
[ax.xaxis.majorTicks[0],ax.xaxis.minorTicks[0]])
3008+
if (xticklabel_toporax.xaxis.get_label_position()=='top'):
3009+
bb=ax.xaxis.get_tightbbox(renderer)
3010+
ifbbisNone:
3011+
# Extent of the outline for colorbars, of the axes otherwise.
3012+
bb=ax.spines.get("outline",ax).get_window_extent()
3013+
top=max(top,bb.ymax)
3014+
29993015
fortitleintitles:
30003016
x,_=title.get_position()
30013017
# need to start again in case of window resizing
30023018
title.set_position((x,1.0))
3003-
top=-np.inf
3004-
foraxinaxs:
3005-
bb=None
3006-
if (ax.xaxis.get_ticks_position()in ['top','unknown']
3007-
orax.xaxis.get_label_position()=='top'):
3008-
bb=ax.xaxis.get_tightbbox(renderer)
3009-
ifbbisNone:
3010-
# Extent of the outline for colorbars, of the axes otherwise.
3011-
bb=ax.spines.get("outline",ax).get_window_extent()
3012-
top=max(top,bb.ymax)
3013-
iftitle.get_text():
3019+
iftitle.get_text():
3020+
foraxinaxs:
30143021
ax.yaxis.get_tightbbox(renderer)# update offsetText
30153022
ifax.yaxis.offsetText.get_text():
30163023
bb=ax.yaxis.offsetText.get_tightbbox(renderer)

‎lib/matplotlib/tests/test_axes.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7118,6 +7118,18 @@ def test_title_no_move_off_page():
71187118
asserttt.get_position()[1]==1.0
71197119

71207120

7121+
deftest_title_inset_ax():
7122+
# Title should be above any child axes
7123+
mpl.rcParams['axes.titley']=None
7124+
fig,ax=plt.subplots()
7125+
ax.set_title('Title')
7126+
fig.draw_without_rendering()
7127+
assertax.title.get_position()[1]==1
7128+
ax.inset_axes([0,1,1,0.1])
7129+
fig.draw_without_rendering()
7130+
assertax.title.get_position()[1]==1.1
7131+
7132+
71217133
deftest_offset_label_color():
71227134
# Tests issue 6440
71237135
fig,ax=plt.subplots()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp