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

Commitc81cc57

Browse files
authored
Merge pull request#23282 from meeseeksmachine/auto-backport-of-pr-22865-on-v3.5.x
Backport PR#22865 on branch v3.5.x (Fix issue with colorbar extend and drawedges)
2 parents02219ee +de4c559 commitc81cc57

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

‎lib/matplotlib/colorbar.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -627,8 +627,12 @@ def _add_solids(self, X, Y, C):
627627
ifnotself.drawedges:
628628
iflen(self._y)>=self.n_rasterize:
629629
self.solids.set_rasterized(True)
630-
self.dividers.set_segments(
631-
np.dstack([X,Y])[1:-1]ifself.drawedgeselse [])
630+
ifself.drawedges:
631+
start_idx=0ifself._extend_lower()else1
632+
end_idx=len(X)ifself._extend_upper()else-1
633+
self.dividers.set_segments(np.dstack([X,Y])[start_idx:end_idx])
634+
else:
635+
self.dividers.set_segments([])
632636

633637
def_add_solids_patches(self,X,Y,C,mappable):
634638
hatches=mappable.hatches*len(C)# Have enough hatches.

‎lib/matplotlib/tests/test_colorbar.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,30 @@ def test_proportional_colorbars():
929929
fig.colorbar(CS3,spacing=spacings[j],ax=axs[i,j])
930930

931931

932+
@pytest.mark.parametrize("extend, coloroffset, res", [
933+
('both',1, [np.array([[0.,0.], [0.,1.]]),
934+
np.array([[1.,0.], [1.,1.]]),
935+
np.array([[2.,0.], [2.,1.]])]),
936+
('min',0, [np.array([[0.,0.], [0.,1.]]),
937+
np.array([[1.,0.], [1.,1.]])]),
938+
('max',0, [np.array([[1.,0.], [1.,1.]]),
939+
np.array([[2.,0.], [2.,1.]])]),
940+
('neither',-1, [np.array([[1.,0.], [1.,1.]])])
941+
])
942+
deftest_colorbar_extend_drawedges(extend,coloroffset,res):
943+
cmap=plt.get_cmap("viridis")
944+
bounds=np.arange(3)
945+
nb_colors=len(bounds)+coloroffset
946+
colors=cmap(np.linspace(100,255,nb_colors).astype(int))
947+
cmap,norm=mcolors.from_levels_and_colors(bounds,colors,extend=extend)
948+
949+
plt.figure(figsize=(5,1))
950+
ax=plt.subplot(111)
951+
cbar=Colorbar(ax,cmap=cmap,norm=norm,orientation='horizontal',
952+
drawedges=True)
953+
assertnp.all(np.equal(cbar.dividers.get_segments(),res))
954+
955+
932956
deftest_negative_boundarynorm():
933957
fig,ax=plt.subplots(figsize=(1,3))
934958
cmap=plt.get_cmap("viridis")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp