🌐 AI搜索 & 代理 主页
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3631,11 +3631,10 @@ def rgb_to_hsv(arr):
f"shape {arr.shape} was found.")

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

out = np.zeros_like(arr)
arr_max = arr.max(-1)
Expand Down
5 changes: 5 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,11 @@ def test_rgb_hsv_round_trip():
tt, mcolors.rgb_to_hsv(mcolors.hsv_to_rgb(tt)))


def test_rgb_to_hsv_int():
# Test that int rgb values (still range 0-1) are processed correctly.
assert_array_equal(mcolors.rgb_to_hsv((0, 1, 0)), (1/3, 1, 1)) # green


def test_autoscale_masked():
# Test for #2336. Previously fully masked data would trigger a ValueError.
data = np.ma.masked_all((12, 20))
Expand Down
Loading