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

Commit3b38089

Browse files
authored
Merge pull request#16466 from jklymak/auto-backport-of-pr-16392-on-v3.2.x
Backport PR#16392: FIX colorbars for Norms that do not have a scale.
2 parents173aa99 +c4867bd commit3b38089

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

‎lib/matplotlib/colorbar.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ def __init__(self, ax, cmap=None,
485485
self.locator=None
486486
self.formatter=None
487487
self._manual_tick_data_values=None
488+
self.__scale=None# linear, log10 for now. Hopefully more?
488489

489490
ifticklocation=='auto':
490491
ticklocation='bottom'iforientation=='horizontal'else'right'
@@ -611,11 +612,9 @@ def _use_auto_colorbar_locator(self):
611612
Return if we should use an adjustable tick locator or a fixed
612613
one. (check is used twice so factored out here...)
613614
"""
614-
contouring= ((self.boundariesisnotNone)and
615-
(self.spacing=='uniform'))
616-
return (((type(self.norm)==colors.Normalize)
617-
or (type(self.norm)==colors.LogNorm))
618-
andnotcontouring)
615+
contouring=self.boundariesisnotNoneandself.spacing=='uniform'
616+
return (type(self.norm)in [colors.Normalize,colors.LogNorm]and
617+
notcontouring)
619618

620619
def_reset_locator_formatter_scale(self):
621620
"""
@@ -631,9 +630,14 @@ def _reset_locator_formatter_scale(self):
631630
self.ax.set_xscale('log')
632631
self.ax.set_yscale('log')
633632
self.minorticks_on()
633+
self.__scale='log'
634634
else:
635635
self.ax.set_xscale('linear')
636636
self.ax.set_yscale('linear')
637+
iftype(self.norm)iscolors.Normalize:
638+
self.__scale='linear'
639+
else:
640+
self.__scale='manual'
637641

638642
defupdate_ticks(self):
639643
"""
@@ -1123,13 +1127,13 @@ def _mesh(self):
11231127
else:
11241128
y=self._proportional_y()
11251129
xmid=np.array([0.5])
1126-
try:
1130+
ifself.__scale!='manual':
11271131
y=norm.inverse(y)
11281132
x=norm.inverse(x)
11291133
xmid=norm.inverse(xmid)
1130-
exceptValueError:
1131-
#occurs for norms that don't havean inverse, in
1132-
#which case manually scale:
1134+
else:
1135+
#if a norm doesn't havea named scale, or
1136+
#we are not using a norm
11331137
dv=self.vmax-self.vmin
11341138
x=x*dv+self.vmin
11351139
y=y*dv+self.vmin

‎lib/matplotlib/tests/test_colorbar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ def test_colorbar_get_ticks():
375375
data=np.arange(1200).reshape(30,40)
376376
levels= [0,200,400,600,800,1000,1200]
377377

378-
plt.subplot()
379378
plt.contourf(data,levels=levels)
380379

381380
# testing getter for user set ticks

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp