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

Commit6934853

Browse files
committed
Added test for cmap.n_variates == 0 in colorizer
1 parent9409d4c commit6934853

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

‎lib/matplotlib/colorizer.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ def _ensure_norm(norm, n_components=1):
766766
scale_cls=_api.check_getitem(scale._scale_mapping,norm=norm)
767767
return_auto_norm_from_scale(scale_cls)()
768768
returnnorm
769-
else:#n_components > 1
769+
elifn_components>1:
770770
ifnotnp.iterable(norm):
771771
_api.check_isinstance((colors.MultiNorm,None,tuple),norm=norm)
772772
ifnormisNone:
@@ -777,6 +777,9 @@ def _ensure_norm(norm, n_components=1):
777777
returnnorm
778778
raiseValueError(
779779
f"Invalid norm for multivariate colormap with{n_components} inputs")
780+
else:# n_components == 0
781+
raiseValueError(
782+
"Invalid cmap. A colorizer object must have a cmap with `n_variates` >= 1")
780783

781784

782785
def_ensure_cmap(cmap,accept_multivariate=False):

‎lib/matplotlib/tests/test_colors.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,16 @@ def test_colorizer_multinorm_explicit():
21992199
assert_array_almost_equal(ca.to_rgba(data),res)
22002200

22012201

2202+
deftest_invalid_cmap_n_components_zero():
2203+
classCustomColormap(mcolors.Colormap):
2204+
def__init__(self):
2205+
super().__init__("custom")
2206+
self.n_variates=0
2207+
2208+
withpytest.raises(ValueError,match='`n_variates` >= 1'):
2209+
ca=mcolorizer.Colorizer(CustomColormap())
2210+
2211+
22022212
deftest_colorizer_bivar_cmap():
22032213
ca=mcolorizer.Colorizer('BiOrangeBlue', [mcolors.Normalize(),'log'])
22042214

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp