Skip to content

Use standard property alias machinery in contour(). #30433

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 1 commit into from
Aug 24, 2025
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy