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

Commitf41edb6

Browse files
committed
FIX: colorbar with boundary norm, proportional, extend
1 parent039c94a commitf41edb6

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

‎lib/matplotlib/colorbar.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,9 @@ def _proportional_y(self):
11981198
a proportional colorbar, plus extension lengths if required:
11991199
"""
12001200
ifisinstance(self.norm,colors.BoundaryNorm):
1201-
y= (self._boundaries-self._boundaries[0])
1202-
y=y/ (self._boundaries[-1]-self._boundaries[0])
1201+
y= (self._boundaries-self._boundaries[self._inside][0])
1202+
y=y/ (self._boundaries[self._inside][-1]-
1203+
self._boundaries[self._inside][0])
12031204
# need yscaled the same as the axes scale to get
12041205
# the extend lengths.
12051206
ifself.spacing=='uniform':

‎lib/matplotlib/tests/test_colorbar.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,3 +827,30 @@ def test_aspects():
827827
np.testing.assert_almost_equal(
828828
cb[1][0].ax.get_position(original=False).height*2,
829829
cb[1][2].ax.get_position(original=False).height,decimal=2)
830+
831+
832+
@image_comparison(['proportional_colorbars.png'],remove_text=True,
833+
style='mpl20')
834+
deftest_proportional_colorbars():
835+
836+
x=y=np.arange(-3.0,3.01,0.025)
837+
X,Y=np.meshgrid(x,y)
838+
Z1=np.exp(-X**2-Y**2)
839+
Z2=np.exp(-(X-1)**2- (Y-1)**2)
840+
Z= (Z1-Z2)*2
841+
842+
levels= [-1.25,-0.5,-0.125,0.125,0.5,1.25]
843+
cmap=mcolors.ListedColormap(
844+
['0.3','0.5','white','lightblue','steelblue'])
845+
cmap.set_under('darkred')
846+
cmap.set_over('crimson')
847+
norm=mcolors.BoundaryNorm(levels,cmap.N)
848+
849+
extends= ['neither','both']
850+
spacings= ['uniform','proportional']
851+
fig,axs=plt.subplots(2,2)
852+
foriinrange(2):
853+
forjinrange(2):
854+
CS3=axs[i,j].contourf(X,Y,Z,levels,cmap=cmap,norm=norm,
855+
extend=extends[i])
856+
fig.colorbar(CS3,spacing=spacings[j],ax=axs[i,j])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp