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

Commit00cdf28

Browse files
authored
Merge pull request#22865 from matplotlib/drawedgesextend
Fix issue with colorbar extend and drawedges
2 parentsa1747a5 +c6729ba commit00cdf28

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
@@ -651,8 +651,12 @@ def _add_solids(self, X, Y, C):
651651
ifnotself.drawedges:
652652
iflen(self._y)>=self.n_rasterize:
653653
self.solids.set_rasterized(True)
654-
self.dividers.set_segments(
655-
np.dstack([X,Y])[1:-1]ifself.drawedgeselse [])
654+
ifself.drawedges:
655+
start_idx=0ifself._extend_lower()else1
656+
end_idx=len(X)ifself._extend_upper()else-1
657+
self.dividers.set_segments(np.dstack([X,Y])[start_idx:end_idx])
658+
else:
659+
self.dividers.set_segments([])
656660

657661
def_add_solids_patches(self,X,Y,C,mappable):
658662
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
@@ -931,6 +931,30 @@ def test_proportional_colorbars():
931931
fig.colorbar(CS3,spacing=spacings[j],ax=axs[i,j])
932932

933933

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp