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

Commit97a580c

Browse files
authored
Merge pull request#12159 from jklymak/fix-check-norm-autolabels
FIX: colorbar re-check norm before draw for autolabels
2 parentsfbeda64 +3add532 commit97a580c

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

‎lib/matplotlib/colorbar.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ def tick_values(self, vmin, vmax):
240240
vmin=max(vmin,self._colorbar.norm.vmin)
241241
vmax=min(vmax,self._colorbar.norm.vmax)
242242
ticks=super().tick_values(vmin,vmax)
243-
returnticks[(ticks>=vmin)& (ticks<=vmax)]
243+
rtol= (vmax-vmin)*1e-10
244+
returnticks[(ticks>=vmin-rtol)& (ticks<=vmax+rtol)]
244245

245246

246247
class_ColorbarAutoMinorLocator(ticker.AutoMinorLocator):
@@ -296,7 +297,10 @@ def tick_values(self, vmin, vmax):
296297
vmin=self._colorbar.norm.vmin
297298
vmax=self._colorbar.norm.vmax
298299
ticks=super().tick_values(vmin,vmax)
299-
returnticks[(ticks>=vmin)& (ticks<=vmax)]
300+
rtol= (np.log10(vmax)-np.log10(vmin))*1e-10
301+
ticks=ticks[(np.log10(ticks)>=np.log10(vmin)-rtol)&
302+
(np.log10(ticks)<=np.log10(vmax)+rtol)]
303+
returnticks
300304

301305

302306
classColorbarBase(cm.ScalarMappable):
@@ -405,7 +409,6 @@ def __init__(self, ax, cmap=None,
405409
else:
406410
self.formatter=format# Assume it is a Formatter
407411
# The rest is in a method so we can recalculate when clim changes.
408-
self.config_axis()
409412
self.draw_all()
410413

411414
def_extend_lower(self):
@@ -439,6 +442,7 @@ def draw_all(self):
439442
# units:
440443
X,Y=self._mesh()
441444
C=self._values[:,np.newaxis]
445+
self.config_axis()
442446
self._config_axes(X,Y)
443447
ifself.filled:
444448
self._add_solids(X,Y,C)
@@ -593,6 +597,7 @@ def _config_axes(self, X, Y):
593597
ax.set_frame_on(False)
594598
ax.set_navigate(False)
595599
xy=self._outline(X,Y)
600+
ax.ignore_existing_data_limits=True
596601
ax.update_datalim(xy)
597602
ax.set_xlim(*ax.dataLim.intervalx)
598603
ax.set_ylim(*ax.dataLim.intervaly)
@@ -1150,7 +1155,6 @@ def update_bruteforce(self, mappable):
11501155
self.set_alpha(mappable.get_alpha())
11511156
self.cmap=mappable.cmap
11521157
self.norm=mappable.norm
1153-
self.config_axis()
11541158
self.draw_all()
11551159
ifisinstance(self.mappable,contour.ContourSet):
11561160
CS=self.mappable

‎lib/matplotlib/tests/test_colorbar.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
frommatplotlib.colorsimportBoundaryNorm,LogNorm,PowerNorm
88
frommatplotlib.cmimportget_cmap
99
frommatplotlib.colorbarimportColorbarBase
10+
frommatplotlib.tickerimportLogLocator,LogFormatter
1011

1112

1213
def_get_cmap_norms():
@@ -411,3 +412,27 @@ def test_colorbar_log_minortick_labels():
411412
r'$\mathdefault{4\times10^{4}}$']
412413
forl,expinzip(lb,expected):
413414
assertl.get_text()==exp
415+
416+
417+
deftest_colorbar_renorm():
418+
x,y=np.ogrid[-4:4:31j,-4:4:31j]
419+
z=120000*np.exp(-x**2-y**2)
420+
421+
fig,ax=plt.subplots()
422+
im=ax.imshow(z)
423+
cbar=fig.colorbar(im)
424+
425+
norm=LogNorm(z.min(),z.max())
426+
im.set_norm(norm)
427+
cbar.set_norm(norm)
428+
cbar.locator=LogLocator()
429+
cbar.formatter=LogFormatter()
430+
cbar.update_normal(im)
431+
assertnp.isclose(cbar.vmin,z.min())
432+
433+
norm=LogNorm(z.min()*1000,z.max()*1000)
434+
im.set_norm(norm)
435+
cbar.set_norm(norm)
436+
cbar.update_normal(im)
437+
assertnp.isclose(cbar.vmin,z.min()*1000)
438+
assertnp.isclose(cbar.vmax,z.max()*1000)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp