Skip to content

Fix colorbar test and color level determination for contour #8737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -1254,11 +1254,11 @@ def _process_colors(self):
i0, i1 = 0, len(self.levels)
if self.filled:
i1 -= 1
# Out of range indices for over and under:
if self.extend in ('both', 'min'):
i0 = -1
if self.extend in ('both', 'max'):
i1 += 1
# Out of range indices for over and under:
if self.extend in ('both', 'min'):
i0 -= 1
if self.extend in ('both', 'max'):
i1 += 1
self.cvalues = list(range(i0, i1))
self.set_norm(colors.NoNorm())
else:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 10 additions & 9 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,21 +168,22 @@ def test_given_colors_levels_and_extends():
levels = [2, 4, 8, 10]

for i, ax in enumerate(axes.flatten()):
plt.sca(ax)

filled = i % 2 == 0.
extend = ['neither', 'min', 'max', 'both'][i // 2]

if filled:
last_color = -1 if extend in ['min', 'max'] else None
plt.contourf(data, colors=colors[:last_color], levels=levels,
extend=extend)
# If filled, we have 3 colors with no extension,
# 4 colors with one extension, and 5 colors with both extensions
first_color = 1 if extend in ['max', 'neither'] else None
last_color = -1 if extend in ['min', 'neither'] else None
c = ax.contourf(data, colors=colors[first_color:last_color],
levels=levels, extend=extend)
else:
last_level = -1 if extend == 'both' else None
plt.contour(data, colors=colors, levels=levels[:last_level],
extend=extend)
# If not filled, we have 4 levels and 4 colors
c = ax.contour(data, colors=colors[:-1],
levels=levels, extend=extend)

plt.colorbar()
plt.colorbar(c, ax=ax)


@image_comparison(baseline_images=['contour_datetime_axis'],
Expand Down