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

Commitd8629e9

Browse files
authored
Merge pull request#22844 from QuLogic/auto-backport-of-pr-22313-on-v3.5.x
Backport PR#22313 on branch v3.5.x (Fix colorbar exponents)
2 parents08cb870 +f6c755c commitd8629e9

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

‎lib/matplotlib/axes/_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,11 @@ def _update_title_position(self, renderer):
29902990
orax.xaxis.get_label_position()=='top'):
29912991
bb=ax.xaxis.get_tightbbox(renderer)
29922992
else:
2993-
bb=ax.get_window_extent(renderer)
2993+
if'outline'inax.spines:
2994+
# Special case for colorbars:
2995+
bb=ax.spines['outline'].get_window_extent()
2996+
else:
2997+
bb=ax.get_window_extent(renderer)
29942998
ifbbisnotNone:
29952999
top=max(top,bb.ymax)
29963000
iftop<0:

‎lib/matplotlib/axis.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,8 +2380,13 @@ def _update_offset_text_position(self, bboxes, bboxes2):
23802380
Update the offset_text position based on the sequence of bounding
23812381
boxes of all the ticklabels
23822382
"""
2383-
x,y=self.offsetText.get_position()
2384-
top=self.axes.bbox.ymax
2383+
x,_=self.offsetText.get_position()
2384+
if'outline'inself.axes.spines:
2385+
# Special case for colorbars:
2386+
bbox=self.axes.spines['outline'].get_window_extent()
2387+
else:
2388+
bbox=self.axes.bbox
2389+
top=bbox.ymax
23852390
self.offsetText.set_position(
23862391
(x,top+self.OFFSETTEXTPAD*self.figure.dpi/72)
23872392
)

‎lib/matplotlib/tests/test_colorbar.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,3 +968,30 @@ def test_boundaries():
968968
fig,ax=plt.subplots(figsize=(2,2))
969969
pc=ax.pcolormesh(np.random.randn(10,10),cmap='RdBu_r')
970970
cb=fig.colorbar(pc,ax=ax,boundaries=np.linspace(-3,3,7))
971+
972+
973+
deftest_offset_text_loc():
974+
plt.style.use('mpl20')
975+
fig,ax=plt.subplots()
976+
np.random.seed(seed=19680808)
977+
pc=ax.pcolormesh(np.random.randn(10,10)*1e6)
978+
cb=fig.colorbar(pc,location='right',extend='max')
979+
fig.draw_without_rendering()
980+
# check that the offsetText is in the proper place above the
981+
# colorbar axes. In this case the colorbar axes is the same
982+
# height as the parent, so use the parents bbox.
983+
assertcb.ax.yaxis.offsetText.get_position()[1]>ax.bbox.y1
984+
985+
986+
deftest_title_text_loc():
987+
plt.style.use('mpl20')
988+
fig,ax=plt.subplots()
989+
np.random.seed(seed=19680808)
990+
pc=ax.pcolormesh(np.random.randn(10,10))
991+
cb=fig.colorbar(pc,location='right',extend='max')
992+
cb.ax.set_title('Aardvark')
993+
fig.draw_without_rendering()
994+
# check that the title is in the proper place above the
995+
# colorbar axes, including its extend triangles....
996+
assert (cb.ax.title.get_window_extent(fig.canvas.get_renderer()).ymax>
997+
cb.ax.spines['outline'].get_window_extent().ymax)

‎tutorials/introductory/usage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def my_plotter(ax, data1, data2, param_dict):
502502

503503
pc=axs[1,1].scatter(data1,data2,c=data3,cmap='RdBu_r')
504504
fig.colorbar(pc,ax=axs[1,1],extend='both')
505-
axs[1,1].set_title('scatter()');
505+
axs[1,1].set_title('scatter()')
506506

507507
##############################################################################
508508
# Colormaps

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp