-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Warn about unused kwargs in contour methods #7728
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -800,32 +800,32 @@ def __init__(self, ax, *args, **kwargs): | |
:attr:`matplotlib.contour.QuadContourSet.contour_doc`. | ||
""" | ||
self.ax = ax | ||
self.levels = kwargs.get('levels', None) | ||
self.filled = kwargs.get('filled', False) | ||
self.linewidths = kwargs.get('linewidths', None) | ||
self.linestyles = kwargs.get('linestyles', None) | ||
|
||
self.hatches = kwargs.get('hatches', [None]) | ||
|
||
self.alpha = kwargs.get('alpha', None) | ||
self.origin = kwargs.get('origin', None) | ||
self.extent = kwargs.get('extent', None) | ||
cmap = kwargs.get('cmap', None) | ||
self.colors = kwargs.get('colors', None) | ||
norm = kwargs.get('norm', None) | ||
vmin = kwargs.get('vmin', None) | ||
vmax = kwargs.get('vmax', None) | ||
self.extend = kwargs.get('extend', 'neither') | ||
self.antialiased = kwargs.get('antialiased', None) | ||
self.levels = kwargs.pop('levels', None) | ||
self.filled = kwargs.pop('filled', False) | ||
self.linewidths = kwargs.pop('linewidths', None) | ||
self.linestyles = kwargs.pop('linestyles', None) | ||
|
||
self.hatches = kwargs.pop('hatches', [None]) | ||
|
||
self.alpha = kwargs.pop('alpha', None) | ||
self.origin = kwargs.pop('origin', None) | ||
self.extent = kwargs.pop('extent', None) | ||
cmap = kwargs.pop('cmap', None) | ||
self.colors = kwargs.pop('colors', None) | ||
norm = kwargs.pop('norm', None) | ||
vmin = kwargs.pop('vmin', None) | ||
vmax = kwargs.pop('vmax', None) | ||
self.extend = kwargs.pop('extend', 'neither') | ||
self.antialiased = kwargs.pop('antialiased', None) | ||
if self.antialiased is None and self.filled: | ||
self.antialiased = False # eliminate artifacts; we are not | ||
# stroking the boundaries. | ||
# The default for line contours will be taken from | ||
# the LineCollection default, which uses the | ||
# rcParams['lines.antialiased'] | ||
|
||
self.nchunk = kwargs.get('nchunk', 0) | ||
self.locator = kwargs.get('locator', None) | ||
self.nchunk = kwargs.pop('nchunk', 0) | ||
self.locator = kwargs.pop('locator', None) | ||
if (isinstance(norm, colors.LogNorm) | ||
or isinstance(self.locator, ticker.LogLocator)): | ||
self.logscale = True | ||
|
@@ -848,9 +848,9 @@ def __init__(self, ax, *args, **kwargs): | |
if self.origin == 'image': | ||
self.origin = mpl.rcParams['image.origin'] | ||
|
||
self._transform = kwargs.get('transform', None) | ||
self._transform = kwargs.pop('transform', None) | ||
|
||
self._process_args(*args, **kwargs) | ||
kwargs = self._process_args(*args, **kwargs) | ||
self._process_levels() | ||
|
||
if self.colors is not None: | ||
|
@@ -915,11 +915,12 @@ def __init__(self, ax, *args, **kwargs): | |
if self.allkinds is None: | ||
self.allkinds = [None] * len(self.allsegs) | ||
|
||
# Default zorder taken from Collection | ||
zorder = kwargs.pop('zorder', 1) | ||
for level, level_upper, segs, kinds in \ | ||
zip(lowers, uppers, self.allsegs, self.allkinds): | ||
paths = self._make_paths(segs, kinds) | ||
# Default zorder taken from Collection | ||
zorder = kwargs.get('zorder', 1) | ||
|
||
col = mcoll.PathCollection( | ||
paths, | ||
antialiaseds=(self.antialiased,), | ||
|
@@ -936,10 +937,10 @@ def __init__(self, ax, *args, **kwargs): | |
aa = self.antialiased | ||
if aa is not None: | ||
aa = (self.antialiased,) | ||
# Default zorder taken from LineCollection | ||
zorder = kwargs.pop('zorder', 2) | ||
for level, width, lstyle, segs in \ | ||
zip(self.levels, tlinewidths, tlinestyles, self.allsegs): | ||
# Default zorder taken from LineCollection | ||
zorder = kwargs.get('zorder', 2) | ||
col = mcoll.LineCollection( | ||
segs, | ||
antialiaseds=aa, | ||
|
@@ -960,6 +961,13 @@ def __init__(self, ax, *args, **kwargs): | |
|
||
self.changed() # set the colors | ||
|
||
if kwargs: | ||
s = '' | ||
for key, value in kwargs.items(): | ||
s += '"' + str(key) + '"' + ', ' | ||
warnings.warn('The following kwargs were not used by contour: ' + | ||
s) | ||
|
||
def get_transform(self): | ||
""" | ||
Return the :class:`~matplotlib.transforms.Transform` | ||
|
@@ -1068,6 +1076,8 @@ def _process_args(self, *args, **kwargs): | |
self._mins = points.min(axis=0) | ||
self._maxs = points.max(axis=0) | ||
|
||
return kwargs | ||
|
||
def _get_allsegs_and_allkinds(self): | ||
""" | ||
Override in derived classes to create and return allsegs and allkinds. | ||
|
@@ -1431,7 +1441,7 @@ def _process_args(self, *args, **kwargs): | |
self._mins = args[0]._mins | ||
self._maxs = args[0]._maxs | ||
else: | ||
self._corner_mask = kwargs.get('corner_mask', None) | ||
self._corner_mask = kwargs.pop('corner_mask', None) | ||
if self._corner_mask is None: | ||
self._corner_mask = mpl.rcParams['contour.corner_mask'] | ||
|
||
|
@@ -1470,6 +1480,8 @@ def _process_args(self, *args, **kwargs): | |
else: | ||
self._contour_generator = contour_generator | ||
|
||
return kwargs | ||
|
||
def _get_allsegs_and_allkinds(self): | ||
""" | ||
Create and return allsegs and allkinds by calling underlying C code. | ||
|
@@ -1539,7 +1551,7 @@ def _check_xyz(self, args, kwargs): | |
Exception class (here and elsewhere). | ||
""" | ||
x, y = args[:2] | ||
self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) | ||
kwargs = self.ax._process_unit_info(xdata=x, ydata=y, kwargs=kwargs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this case, it's passed as a mutable value, so you don't technically need to return it. It should be the same object coming out as going in. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest renaming the method to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am 👎 on renaming it because it has had the current name for a long time and has always probably had this pop behavior. In any case that change is outside of the scope if this PR. |
||
x = self.ax.convert_xunits(x) | ||
y = self.ax.convert_yunits(y) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could just be
", ".join(map(repr, kwargs))
.