Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a455f1c

Browse files
authored
Merge pull request #7728 from dstansby/unused-kwarg-warnings
ENH: Warn about unused kwargs in contour methods
2 parents 805d20c + 4481344 commit a455f1c

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,6 +1986,7 @@ def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
19861986
# we need to update.
19871987
if ydata is not None:
19881988
self.yaxis.update_units(ydata)
1989+
return kwargs
19891990

19901991
def in_axes(self, mouseevent):
19911992
"""

lib/matplotlib/contour.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -800,32 +800,32 @@ def __init__(self, ax, *args, **kwargs):
800800
:attr:`matplotlib.contour.QuadContourSet.contour_doc`.
801801
"""
802802
self.ax = ax
803-
self.levels = kwargs.get('levels', None)
804-
self.filled = kwargs.get('filled', False)
805-
self.linewidths = kwargs.get('linewidths', None)
806-
self.linestyles = kwargs.get('linestyles', None)
807-
808-
self.hatches = kwargs.get('hatches', [None])
809-
810-
self.alpha = kwargs.get('alpha', None)
811-
self.origin = kwargs.get('origin', None)
812-
self.extent = kwargs.get('extent', None)
813-
cmap = kwargs.get('cmap', None)
814-
self.colors = kwargs.get('colors', None)
815-
norm = kwargs.get('norm', None)
816-
vmin = kwargs.get('vmin', None)
817-
vmax = kwargs.get('vmax', None)
818-
self.extend = kwargs.get('extend', 'neither')
819-
self.antialiased = kwargs.get('antialiased', None)
803+
self.levels = kwargs.pop('levels', None)
804+
self.filled = kwargs.pop('filled', False)
805+
self.linewidths = kwargs.pop('linewidths', None)
806+
self.linestyles = kwargs.pop('linestyles', None)
807+
808+
self.hatches = kwargs.pop('hatches', [None])
809+
810+
self.alpha = kwargs.pop('alpha', None)
811+
self.origin = kwargs.pop('origin', None)
812+
self.extent = kwargs.pop('extent', None)
813+
cmap = kwargs.pop('cmap', None)
814+
self.colors = kwargs.pop('colors', None)
815+
norm = kwargs.pop('norm', None)
816+
vmin = kwargs.pop('vmin', None)
817+
vmax = kwargs.pop('vmax', None)
818+
self.extend = kwargs.pop('extend', 'neither')
819+
self.antialiased = kwargs.pop('antialiased', None)
820820
if self.antialiased is None and self.filled:
821821
self.antialiased = False # eliminate artifacts; we are not
822822
# stroking the boundaries.
823823
# The default for line contours will be taken from
824824
# the LineCollection default, which uses the
825825
# rcParams['lines.antialiased']
826826

827-
self.nchunk = kwargs.get('nchunk', 0)
828-
self.locator = kwargs.get('locator', None)
827+
self.nchunk = kwargs.pop('nchunk', 0)
828+
self.locator = kwargs.pop('locator', None)
829829
if (isinstance(norm, colors.LogNorm)
830830
or isinstance(self.locator, ticker.LogLocator)):
831831
self.logscale = True
@@ -848,9 +848,9 @@ def __init__(self, ax, *args, **kwargs):
848848
if self.origin == 'image':
849849
self.origin = mpl.rcParams['image.origin']
850850

851-
self._transform = kwargs.get('transform', None)
851+
self._transform = kwargs.pop('transform', None)
852852

853-
self._process_args(*args, **kwargs)
853+
kwargs = self._process_args(*args, **kwargs)
854854
self._process_levels()
855855

856856
if self.colors is not None:
@@ -915,11 +915,12 @@ def __init__(self, ax, *args, **kwargs):
915915
if self.allkinds is None:
916916
self.allkinds = [None] * len(self.allsegs)
917917

918+
# Default zorder taken from Collection
919+
zorder = kwargs.pop('zorder', 1)
918920
for level, level_upper, segs, kinds in \
919921
zip(lowers, uppers, self.allsegs, self.allkinds):
920922
paths = self._make_paths(segs, kinds)
921-
# Default zorder taken from Collection
922-
zorder = kwargs.get('zorder', 1)
923+
923924
col = mcoll.PathCollection(
924925
paths,
925926
antialiaseds=(self.antialiased,),
@@ -936,10 +937,10 @@ def __init__(self, ax, *args, **kwargs):
936937
aa = self.antialiased
937938
if aa is not None:
938939
aa = (self.antialiased,)
940+
# Default zorder taken from LineCollection
941+
zorder = kwargs.pop('zorder', 2)
939942
for level, width, lstyle, segs in \
940943
zip(self.levels, tlinewidths, tlinestyles, self.allsegs):
941-
# Default zorder taken from LineCollection
942-
zorder = kwargs.get('zorder', 2)
943944
col = mcoll.LineCollection(
944945
segs,
945946
antialiaseds=aa,
@@ -960,6 +961,11 @@ def __init__(self, ax, *args, **kwargs):
960961

961962
self.changed() # set the colors
962963

964+
if kwargs:
965+
s = ", ".join(map(repr, kwargs))
966+
warnings.warn('The following kwargs were not used by contour: ' +
967+
s)
968+
963969
def get_transform(self):
964970
"""
965971
Return the :class:`~matplotlib.transforms.Transform`
@@ -1068,6 +1074,8 @@ def _process_args(self, *args, **kwargs):
10681074
self._mins = points.min(axis=0)
10691075
self._maxs = points.max(axis=0)
10701076

1077+
return kwargs
1078+
10711079
def _get_allsegs_and_allkinds(self):
10721080
"""
10731081
Override in derived classes to create and return allsegs and allkinds.
@@ -1431,7 +1439,7 @@ def _process_args(self, *args, **kwargs):
14311439
self._mins = args[0]._mins
14321440
self._maxs = args[0]._maxs
14331441
else:
1434-
self._corner_mask = kwargs.get('corner_mask', None)
1442+
self._corner_mask = kwargs.pop('corner_mask', None)
14351443
if self._corner_mask is None:
14361444
self._corner_mask = mpl.rcParams['contour.corner_mask']
14371445

@@ -1470,6 +1478,8 @@ def _process_args(self, *args, **kwargs):
14701478
else:
14711479
self._contour_generator = contour_generator
14721480

1481+
return kwargs
1482+
14731483
def _get_allsegs_and_allkinds(self):
14741484
"""
14751485
Create and return allsegs and allkinds by calling underlying C code.
@@ -1539,7 +1549,7 @@ def _check_xyz(self, args, kwargs):
15391549
Exception class (here and elsewhere).
15401550
"""
15411551
x, y = args[:2]
1542-
self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
1552+
kwargs = self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs)
15431553
x = self.ax.convert_xunits(x)
15441554
y = self.ax.convert_yunits(y)
15451555

lib/matplotlib/tri/tricontour.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def _process_args(self, *args, **kwargs):
5454
self._maxs = [tri.x.max(), tri.y.max()]
5555

5656
self.cppContourGenerator = C
57+
return kwargs
5758

5859
def _get_allsegs_and_allkinds(self):
5960
"""

0 commit comments

Comments
 (0)