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 58b63cc

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

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
@@ -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

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
@@ -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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.