Thanks to visit codestin.com
Credit goes to github.com

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 @@ -3729,11 +3729,10 @@ def hsv_to_rgb(hsv):
f"shape {hsv.shape} was found.")

in_shape = hsv.shape
hsv = np.array(
hsv, copy=False,
dtype=np.promote_types(hsv.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
hsv = np.asarray(hsv, dtype=np.promote_types(hsv.dtype, np.float32))
if hsv.ndim == 1:
hsv = np.expand_dims(hsv, axis=0) # ensure hsv is 2D

h = hsv[..., 0]
s = hsv[..., 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 @@ -946,6 +946,11 @@ def test_rgb_to_hsv_int():
assert_array_equal(mcolors.rgb_to_hsv((0, 1, 0)), (1/3, 1, 1)) # green


def test_hsv_to_rgb_int():
# Test that int hsv values (still range 0-1) are processed correctly.
assert_array_equal(mcolors.hsv_to_rgb((0, 1, 1)), (1, 0, 0)) # red


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