Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2b2f195

Browse filesBrowse files
committed
FIX: check for string color in ContourSet
1 parent 4310fff commit 2b2f195
Copy full SHA for 2b2f195

File tree

Expand file treeCollapse file tree

2 files changed

+20
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-4
lines changed

‎lib/matplotlib/contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/contour.py
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,11 @@ def __init__(self, ax, *args,
702702
self._extend_min = self.extend in ['min', 'both']
703703
self._extend_max = self.extend in ['max', 'both']
704704
if self.colors is not None:
705+
if isinstance(self.colors, str):
706+
colors = [colors]
707+
else:
708+
colors = colors
709+
705710
ncolors = len(self.levels)
706711
if self.filled:
707712
ncolors -= 1
@@ -718,19 +723,19 @@ def __init__(self, ax, *args,
718723
total_levels = (ncolors +
719724
int(self._extend_min) +
720725
int(self._extend_max))
721-
if (len(self.colors) == total_levels and
726+
if (len(colors) == total_levels and
722727
(self._extend_min or self._extend_max)):
723728
use_set_under_over = True
724729
if self._extend_min:
725730
i0 = 1
726731

727-
cmap = mcolors.ListedColormap(self.colors[i0:None], N=ncolors)
732+
cmap = mcolors.ListedColormap(colors[i0:None], N=ncolors)
728733

729734
if use_set_under_over:
730735
if self._extend_min:
731-
cmap.set_under(self.colors[0])
736+
cmap.set_under(colors[0])
732737
if self._extend_max:
733-
cmap.set_over(self.colors[-1])
738+
cmap.set_over(colors[-1])
734739

735740
# label lists must be initialized here
736741
self.labelTexts = []

‎lib/matplotlib/tests/test_contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_contour.py
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ def test_given_colors_levels_and_extends():
171171
plt.colorbar(c, ax=ax)
172172

173173

174+
def test_single_color_and_extend():
175+
z = [[0, 1], [1, 2]]
176+
color = 'green'
177+
levels = [0.5, 1, 1.5]
178+
179+
_, ax = plt.subplots()
180+
cs = ax.contour(z, levels=levels, colors=color, extend='both')
181+
for c in cs.get_edgecolors():
182+
assert same_color(c, color)
183+
184+
174185
@image_comparison(['contour_log_locator.svg'], style='mpl20', remove_text=False)
175186
def test_log_locator_levels():
176187

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.