Skip to content

Commit be6dd20

Browse files
authored
Merge pull request matplotlib#31944 from meeseeksmachine/auto-backport-of-pr-31943-on-v3.11.x
Backport PR matplotlib#31943 on branch v3.11.x (FIX: allow non-strict monotonicity in LinearSegmented.from_list values)
2 parents f4461ce + 0ebdea5 commit be6dd20

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ def from_list(name, colors, N=256, gamma=1.0, *, bad=None, under=None, over=None
12331233
except Exception as e2:
12341234
raise e2 from e
12351235
vals = np.asarray(_vals)
1236-
if np.min(vals) < 0 or np.max(vals) > 1 or np.any(np.diff(vals) <= 0):
1236+
if np.min(vals) < 0 or np.max(vals) > 1 or np.any(np.diff(vals) < 0):
12371237
raise ValueError(
12381238
"the values passed in the (value, color) pairs "
12391239
"must increase monotonically from 0 to 1."

lib/matplotlib/tests/test_colors.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,13 @@ def test_LinearSegmentedColormap_from_list_value_color_tuple():
18281828
)
18291829

18301830

1831+
def test_LinearSegmentedColormap_from_list_repeat_values():
1832+
# Smoke test that we can pass repeated values to make a solid band of color
1833+
# followed by a linear ramp.
1834+
value_color_tuples = [(0, "red"), (0.6, "red"), (0.6, "blue"), (1, "green")]
1835+
mcolors.LinearSegmentedColormap.from_list("lsc", value_color_tuples, N=11)
1836+
1837+
18311838
@image_comparison(['test_norm_abc.png'], remove_text=True, style='_classic_test',
18321839
tol=0 if platform.machine() == 'x86_64' else 0.05)
18331840
def test_norm_abc():

0 commit comments

Comments
 (0)