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

Skip to content

Commit 760e756

Browse files
committed
Update collections.py
Account for inverse (or other) relationships where `np.interp` will not work correctly.
1 parent 9756aca commit 760e756

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/matplotlib/collections.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,8 +1076,10 @@ def legend_elements(self, prop="colors", num="auto",
10761076
cond = ((label_values >= func(arr).min()) &
10771077
(label_values <= func(arr).max()))
10781078
label_values = label_values[cond]
1079-
xarr = np.linspace(arr.min(), arr.max(), 256)
1080-
values = np.interp(label_values, func(xarr), xarr)
1079+
yarr = np.linspace(arr.min(), arr.max(), 256)
1080+
xarr = func(yarr)
1081+
ix = np.argsort(xarr)
1082+
values = np.interp(label_values, xarr[ix], yarr[ix])
10811083

10821084
kw = dict(markeredgewidth=self.get_linewidths()[0],
10831085
alpha=self.get_alpha())

0 commit comments

Comments
 (0)