Skip to content

Commit bbfae9b

Browse files
committed
Merge branch 'v1.0.x'
2 parents 525d9ba + 9e7b1c0 commit bbfae9b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: lib/matplotlib/colors.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1053,19 +1053,21 @@ def rgb_to_hsv(arr):
10531053
convert rgb values in a numpy array to hsv values
10541054
input and output arrays should have shape (M,N,3)
10551055
"""
1056-
out = np.empty_like(arr)
1056+
out = np.zeros_like(arr)
10571057
arr_max = arr.max(-1)
1058+
ipos = arr_max > 0
10581059
delta = arr.ptp(-1)
1059-
s = delta / arr_max
1060-
s[delta==0] = 0
1060+
s = np.zeros_like(delta)
1061+
s[ipos] = delta[ipos] / arr_max[ipos]
1062+
ipos = delta > 0
10611063
# red is max
1062-
idx = (arr[:,:,0] == arr_max)
1064+
idx = (arr[:,:,0] == arr_max) & ipos
10631065
out[idx, 0] = (arr[idx, 1] - arr[idx, 2]) / delta[idx]
10641066
# green is max
1065-
idx = (arr[:,:,1] == arr_max)
1067+
idx = (arr[:,:,1] == arr_max) & ipos
10661068
out[idx, 0] = 2. + (arr[idx, 2] - arr[idx, 0] ) / delta[idx]
10671069
# blue is max
1068-
idx = (arr[:,:,2] == arr_max)
1070+
idx = (arr[:,:,2] == arr_max) & ipos
10691071
out[idx, 0] = 4. + (arr[idx, 0] - arr[idx, 1] ) / delta[idx]
10701072
out[:,:,0] = (out[:,:,0]/6.0) % 1.0
10711073
out[:,:,1] = s

0 commit comments

Comments
 (0)