Skip to content

Commit 58b63cc

Browse files
committed
FIX: check for string color in ContourSet
1 parent cb9cf3b commit 58b63cc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

lib/matplotlib/contour.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,11 @@ def __init__(self, ax, *args,
816816
self._extend_min = self.extend in ['min', 'both']
817817
self._extend_max = self.extend in ['max', 'both']
818818
if self.colors is not None:
819+
if isinstance(self.colors, str):
820+
colors = [colors]
821+
else:
822+
colors = colors
823+
819824
ncolors = len(self.levels)
820825
if self.filled:
821826
ncolors -= 1
@@ -832,19 +837,19 @@ def __init__(self, ax, *args,
832837
total_levels = (ncolors +
833838
int(self._extend_min) +
834839
int(self._extend_max))
835-
if (len(self.colors) == total_levels and
840+
if (len(colors) == total_levels and
836841
(self._extend_min or self._extend_max)):
837842
use_set_under_over = True
838843
if self._extend_min:
839844
i0 = 1
840845

841-
cmap = mcolors.ListedColormap(self.colors[i0:None], N=ncolors)
846+
cmap = mcolors.ListedColormap(colors[i0:None], N=ncolors)
842847

843848
if use_set_under_over:
844849
if self._extend_min:
845-
cmap.set_under(self.colors[0])
850+
cmap.set_under(colors[0])
846851
if self._extend_max:
847-
cmap.set_over(self.colors[-1])
852+
cmap.set_over(colors[-1])
848853

849854
# label lists must be initialized here
850855
self.labelTexts = []

lib/matplotlib/tests/test_contour.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,17 @@ def test_given_colors_levels_and_extends(split_collections):
198198
_maybe_split_collections(split_collections)
199199

200200

201+
def test_single_color_and_extend():
202+
z = [[0, 1], [1, 2]]
203+
color = 'green'
204+
levels = [0.5, 1, 1.5]
205+
206+
_, ax = plt.subplots()
207+
cs = ax.contour(z, levels=levels, colors=color, extend='both')
208+
for c in cs.get_edgecolors():
209+
assert same_color(c, color)
210+
211+
201212
@pytest.mark.parametrize("split_collections", [False, True])
202213
@image_comparison(['contour_log_locator.svg'], style='mpl20', remove_text=False)
203214
def test_log_locator_levels(split_collections):

0 commit comments

Comments
 (0)