Skip to content
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
25 changes: 8 additions & 17 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ def __init__(self, ax, *args,
hatches=(None,), alpha=None, origin=None, extent=None,
cmap=None, colors=None, norm=None, vmin=None, vmax=None,
colorizer=None, extend='neither', antialiased=None, nchunk=0,
locator=None, transform=None, negative_linestyles=None, clip_path=None,
locator=None, transform=None, negative_linestyles=None,
**kwargs):
"""
Draw contour lines or filled regions, depending on
Expand Down Expand Up @@ -656,7 +656,6 @@ def __init__(self, ax, *args,
super().__init__(
antialiaseds=antialiased,
alpha=alpha,
clip_path=clip_path,
transform=transform,
colorizer=colorizer,
)
Expand All @@ -672,6 +671,9 @@ def __init__(self, ax, *args,
self.nchunk = nchunk
self.locator = locator

if "color" in kwargs:
raise _api.kwarg_error("ContourSet.__init__", "color")

if colorizer:
self._set_colorizer_check_keywords(colorizer, cmap=cmap,
norm=norm, vmin=vmin,
Expand Down Expand Up @@ -764,23 +766,18 @@ def __init__(self, ax, *args,
_api.warn_external('linewidths is ignored by contourf')
# Lower and upper contour levels.
lowers, uppers = self._get_lowers_and_uppers()
self.set(
edgecolor="none",
# Default zorder taken from Collection
zorder=kwargs.pop("zorder", 1),
rasterized=kwargs.pop("rasterized", False),
)

self.set(edgecolor="none")
else:
self.set(
facecolor="none",
linewidths=self._process_linewidths(linewidths),
linestyle=self._process_linestyles(linestyles),
label="_nolegend_",
# Default zorder taken from LineCollection, which is higher
# than for filled contours so that lines are displayed on top.
zorder=kwargs.pop("zorder", 2),
label="_nolegend_",
zorder=2,
)
self.set(**kwargs) # Let user-set values override defaults.

self.axes.add_collection(self, autolim=False)
self.sticky_edges.x[:] = [self._mins[0], self._maxs[0]]
Expand All @@ -790,12 +787,6 @@ def __init__(self, ax, *args,

self.changed() # set the colors

if kwargs:
_api.warn_external(
'The following kwargs were not used by contour: ' +
", ".join(map(repr, kwargs))
)

allsegs = property(lambda self: [
[subp.vertices for subp in p._iter_connected_components()]
for p in self.get_paths()])
Expand Down
12 changes: 12 additions & 0 deletions lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,3 +865,15 @@ def test_contourf_rasterize():
circle = mpatches.Circle([0.5, 0.5], 0.5, transform=ax.transAxes)
cs = ax.contourf(data, clip_path=circle, rasterized=True)
assert cs._rasterized


@check_figures_equal(extensions=["png"])
def test_contour_aliases(fig_test, fig_ref):
data = np.arange(100).reshape((10, 10)) ** 2
fig_test.add_subplot().contour(data, linestyle=":")
fig_ref.add_subplot().contour(data, linestyles="dotted")


def test_contour_singular_color():
with pytest.raises(TypeError):
plt.figure().add_subplot().contour([[0, 1], [2, 3]], color="r")
Loading