Skip to content

Commit 1f8ff33

Browse files
authored
Merge pull request matplotlib#30433 from anntzer/ck
Use standard property alias machinery in contour().
2 parents a617ece + b00e066 commit 1f8ff33

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

lib/matplotlib/contour.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def __init__(self, ax, *args,
602602
hatches=(None,), alpha=None, origin=None, extent=None,
603603
cmap=None, colors=None, norm=None, vmin=None, vmax=None,
604604
colorizer=None, extend='neither', antialiased=None, nchunk=0,
605-
locator=None, transform=None, negative_linestyles=None, clip_path=None,
605+
locator=None, transform=None, negative_linestyles=None,
606606
**kwargs):
607607
"""
608608
Draw contour lines or filled regions, depending on
@@ -656,7 +656,6 @@ def __init__(self, ax, *args,
656656
super().__init__(
657657
antialiaseds=antialiased,
658658
alpha=alpha,
659-
clip_path=clip_path,
660659
transform=transform,
661660
colorizer=colorizer,
662661
)
@@ -672,6 +671,9 @@ def __init__(self, ax, *args,
672671
self.nchunk = nchunk
673672
self.locator = locator
674673

674+
if "color" in kwargs:
675+
raise _api.kwarg_error("ContourSet.__init__", "color")
676+
675677
if colorizer:
676678
self._set_colorizer_check_keywords(colorizer, cmap=cmap,
677679
norm=norm, vmin=vmin,
@@ -764,23 +766,18 @@ def __init__(self, ax, *args,
764766
_api.warn_external('linewidths is ignored by contourf')
765767
# Lower and upper contour levels.
766768
lowers, uppers = self._get_lowers_and_uppers()
767-
self.set(
768-
edgecolor="none",
769-
# Default zorder taken from Collection
770-
zorder=kwargs.pop("zorder", 1),
771-
rasterized=kwargs.pop("rasterized", False),
772-
)
773-
769+
self.set(edgecolor="none")
774770
else:
775771
self.set(
776772
facecolor="none",
777773
linewidths=self._process_linewidths(linewidths),
778774
linestyle=self._process_linestyles(linestyles),
775+
label="_nolegend_",
779776
# Default zorder taken from LineCollection, which is higher
780777
# than for filled contours so that lines are displayed on top.
781-
zorder=kwargs.pop("zorder", 2),
782-
label="_nolegend_",
778+
zorder=2,
783779
)
780+
self.set(**kwargs) # Let user-set values override defaults.
784781

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

791788
self.changed() # set the colors
792789

793-
if kwargs:
794-
_api.warn_external(
795-
'The following kwargs were not used by contour: ' +
796-
", ".join(map(repr, kwargs))
797-
)
798-
799790
allsegs = property(lambda self: [
800791
[subp.vertices for subp in p._iter_connected_components()]
801792
for p in self.get_paths()])

lib/matplotlib/tests/test_contour.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,3 +865,15 @@ def test_contourf_rasterize():
865865
circle = mpatches.Circle([0.5, 0.5], 0.5, transform=ax.transAxes)
866866
cs = ax.contourf(data, clip_path=circle, rasterized=True)
867867
assert cs._rasterized
868+
869+
870+
@check_figures_equal(extensions=["png"])
871+
def test_contour_aliases(fig_test, fig_ref):
872+
data = np.arange(100).reshape((10, 10)) ** 2
873+
fig_test.add_subplot().contour(data, linestyle=":")
874+
fig_ref.add_subplot().contour(data, linestyles="dotted")
875+
876+
877+
def test_contour_singular_color():
878+
with pytest.raises(TypeError):
879+
plt.figure().add_subplot().contour([[0, 1], [2, 3]], color="r")

0 commit comments

Comments
 (0)