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

Commitcd66f15

Browse files
authored
Merge pull request#30815 from timhoffm/mnt-rgb_to_hsv_int
MNT: Fix handling of ints in rgb_to_hsv()
2 parents875379d +4544674 commitcd66f15

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

‎lib/matplotlib/colors.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,11 +3631,10 @@ def rgb_to_hsv(arr):
36313631
f"shape{arr.shape} was found.")
36323632

36333633
in_shape=arr.shape
3634-
arr=np.array(
3635-
arr,copy=False,
3636-
dtype=np.promote_types(arr.dtype,np.float32),# Don't work on ints.
3637-
ndmin=2,# In case input was 1D.
3638-
)
3634+
# ensure numerics are done at least on float32; ints are cast as well
3635+
arr=np.asarray(arr,dtype=np.promote_types(arr.dtype,np.float32))
3636+
ifarr.ndim==1:
3637+
arr=np.expand_dims(arr,axis=0)# ensure arr is 2D
36393638

36403639
out=np.zeros_like(arr)
36413640
arr_max=arr.max(-1)

‎lib/matplotlib/tests/test_colors.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,11 @@ def test_rgb_hsv_round_trip():
947947
tt,mcolors.rgb_to_hsv(mcolors.hsv_to_rgb(tt)))
948948

949949

950+
deftest_rgb_to_hsv_int():
951+
# Test that int rgb values (still range 0-1) are processed correctly.
952+
assert_array_equal(mcolors.rgb_to_hsv((0,1,0)), (1/3,1,1))# green
953+
954+
950955
deftest_autoscale_masked():
951956
# Test for #2336. Previously fully masked data would trigger a ValueError.
952957
data=np.ma.masked_all((12,20))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp