From 2c24a7c13645fbf0c79bb102274604c3f37b70d2 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Thu, 6 Dec 2012 12:17:41 -0800 Subject: [PATCH 1/4] removed deprecated methods from the axes module. Added some DeprecatedWarnings in places where there should have been some --- lib/matplotlib/axes.py | 131 +++++++++++------------------------------ 1 file changed, 34 insertions(+), 97 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index ed2d393e2be6..e32bae86b592 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -139,25 +139,6 @@ def _process_plot_format(fmt): return linestyle, marker, color -def set_default_color_cycle(clist): - """ - Change the default cycle of colors that will be used by the plot - command. This must be called before creating the - :class:`Axes` to which it will apply; it will - apply to all future axes. - - *clist* is a sequence of mpl color specifiers. - - See also: :meth:`~matplotlib.axes.Axes.set_color_cycle`. - - .. Note:: Deprecated 2010/01/03. - Set rcParams['axes.color_cycle'] directly. - - """ - rcParams['axes.color_cycle'] = clist - warnings.warn("Set rcParams['axes.color_cycle'] directly", mplDeprecation) - - class _process_plot_var_args(object): """ Process variable length arguments to the plot command, so that @@ -282,12 +263,11 @@ def _makefill(self, x, y, kw, kwargs): facecolor = kw['color'] except KeyError: facecolor = self.color_cycle.next() - seg = mpatches.Polygon(np.hstack( - (x[:, np.newaxis], y[:, np.newaxis])), - facecolor=facecolor, - fill=True, - closed=kw['closed'] - ) + seg = mpatches.Polygon(np.hstack((x[:, np.newaxis], + y[:, np.newaxis])), + facecolor=facecolor, + fill=True, + closed=kw['closed']) self.set_patchprops(seg, **kwargs) return seg @@ -586,9 +566,9 @@ def _set_lim_and_transforms(self): self.transData = self.transScale + (self.transLimits + self.transAxes) self._xaxis_transform = mtransforms.blended_transform_factory( - self.transData, self.transAxes) + self.transData, self.transAxes) self._yaxis_transform = mtransforms.blended_transform_factory( - self.transAxes, self.transData) + self.transAxes, self.transData) def get_xaxis_transform(self, which='grid'): """ @@ -1067,11 +1047,16 @@ def set_aspect(self, aspect, adjustable=None, anchor=None): etc. ===== ===================== + .. deprecated:: 1.2 + the option 'normal' for aspect is deprecated. Use 'auto' instead. """ - if aspect in ('normal', 'auto'): + if aspect == 'normal': + raise DeprecationWarning("Use 'auto' instead of 'normal' for " + "aspect. Will be removed in 1.4.x") self._aspect = 'auto' - elif aspect == 'equal': - self._aspect = 'equal' + + elif aspect in ('equal', 'auto'): + self._aspect = aspect else: self._aspect = float(aspect) # raise ValueError if necessary @@ -1370,14 +1355,6 @@ def axis(self, *v, **kwargs): return v - def get_child_artists(self): - """ - Return a list of artists the axes contains. - - .. deprecated:: 0.98 - """ - raise mplDeprecation('Use get_children instead') - def get_frame(self): """Return the axes Rectangle frame""" warnings.warn('use ax.patch instead', mplDeprecation) @@ -3108,30 +3085,6 @@ def set_cursor_props(self, *args): c = mcolors.colorConverter.to_rgba(c) self._cursorProps = lw, c - def connect(self, s, func): - """ - Register observers to be notified when certain events occur. Register - with callback functions with the following signatures. The function - has the following signature:: - - func(ax) # where ax is the instance making the callback. - - The following events can be connected to: - - 'xlim_changed','ylim_changed' - - The connection id is is returned - you can use this with - disconnect to disconnect from the axes event - - """ - raise mplDeprecation('use the callbacks CallbackRegistry instance ' - 'instead') - - def disconnect(self, cid): - """disconnect from the Axes event.""" - raise mplDeprecation('use the callbacks CallbackRegistry instance ' - 'instead') - def get_children(self): """return a list of child artists""" children = [] @@ -3180,9 +3133,6 @@ def pick(self, *args): each child artist will fire a pick event if mouseevent is over the artist and the artist has picker set """ - if len(args) > 1: - raise mplDeprecation('New pick API implemented -- ' - 'see API_CHANGES in the src distribution') martist.Artist.pick(self, args[0]) ### Labelling @@ -3679,10 +3629,6 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid', .. plot:: mpl_examples/pylab_examples/hline_demo.py """ - if kwargs.get('fmt') is not None: - raise mplDeprecation('hlines now uses a ' - 'collections.LineCollection and not a ' - 'list of Line2D to draw; see API_CHANGES') # We do the conversion first since not all unitized data is uniform # process the unit information @@ -3761,11 +3707,6 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid', %(LineCollection)s """ - if kwargs.get('fmt') is not None: - raise mplDeprecation('vlines now uses a ' - 'collections.LineCollection and not a ' - 'list of Line2D to draw; see API_CHANGES') - self._process_unit_info(xdata=x, ydata=[ymin, ymax], kwargs=kwargs) # We do the conversion first since not all unitized data is uniform @@ -5970,9 +5911,8 @@ def dopatch(xs, ys): @docstring.dedent_interpd def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None, - vmin=None, vmax=None, alpha=None, linewidths=None, - faceted=True, verts=None, - **kwargs): + vmin=None, vmax=None, alpha=None, linewidths=None, + verts=None, **kwargs): """ Make a scatter plot. @@ -6095,13 +6035,15 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None, else: colors = mcolors.colorConverter.to_rgba_array(c, alpha) - if faceted: - edgecolors = None - else: - edgecolors = 'none' - warnings.warn( - '''replace "faceted=False" with "edgecolors='none'"''', - mplDeprecation) # 2008/04/18 + faceted = kwargs.pop('faceted', None) + if faceted is not None: + warnings.warn("The faceted option is deprecated. " + "Please use edgecolor instead. Will " + "be remove in 1.4", mplDeprecation) + if faceted: + edgecolors = None + else: + edgecolors = 'none' # to be API compatible if marker is None and not (verts is None): @@ -7319,6 +7261,9 @@ def pcolor(self, *args, **kwargs): cmap = kwargs.pop('cmap', None) vmin = kwargs.pop('vmin', None) vmax = kwargs.pop('vmax', None) + if 'shading' in kwargs: + raise DeprecationWarning("Use edgecolors instead of shading. " + "Will be removed in 1.4") shading = kwargs.pop('shading', 'flat') X, Y, C = self._pcolorargs('pcolor', *args) @@ -7363,14 +7308,17 @@ def pcolor(self, *args, **kwargs): kwargs['linewidths'] = kwargs.pop('linewidth') kwargs.setdefault('linewidths', linewidths) + if shading == 'faceted': edgecolors = 'k', else: edgecolors = 'none' + if 'edgecolor' in kwargs: kwargs['edgecolors'] = kwargs.pop('edgecolor') ec = kwargs.setdefault('edgecolors', edgecolors) + # aa setting will default via collections to patch.antialiased # unless the boundary is not stroked, in which case the # default will be False; with unstroked boundaries, aa @@ -7893,8 +7841,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, Either an integer number of bins or a sequence giving the bins. If *bins* is an integer, *bins* + 1 bin edges will be returned, consistent with :func:`numpy.histogram` - for numpy version >= 1.3, and with the *new* = True argument - in earlier versions. + for numpy version >= 1.3. Unequally spaced bins are supported if *bins* is a sequence. *range*: @@ -8035,11 +7982,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, raise ValueError( "orientation kwarg %s is not recognized" % orientation) - if kwargs.get('width') is not None: - raise mplDeprecation( - 'hist now uses the rwidth to give relative width ' - 'and not absolute width') - if histtype == 'barstacked' and not stacked: stacked = True @@ -8124,8 +8066,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, # We will handle the normed kwarg within mpl until we # get to the point of requiring numpy >= 1.5. hist_kwargs = dict(range=bin_range) - if np.__version__ < "1.3": # version 1.1 and 1.2 - hist_kwargs['new'] = True n = [] mlast = bottom @@ -8185,6 +8125,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, if align == 'mid' or align == 'edge': boffset += 0.5 * totwidth + elif align == 'right': boffset += totwidth @@ -8767,10 +8708,6 @@ def spy(self, Z, precision=0, marker=None, markersize=None, :func:`~matplotlib.pyplot.plot` For plotting options """ - if precision is None: - precision = 0 - warnings.warn("Use precision=0 instead of None", mplDeprecation) - # 2008/10/03 if marker is None and markersize is None and hasattr(Z, 'tocoo'): marker = 's' if marker is None and markersize is None: From e0334274784b82726c9f3477625863fd1523d061 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Sat, 8 Dec 2012 14:39:38 -0800 Subject: [PATCH 2/4] Use the new matplotlib deprecation warning --- lib/matplotlib/axes.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index e32bae86b592..d0ecd08e4ea2 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -10,6 +10,8 @@ import matplotlib rcParams = matplotlib.rcParams +from matplotlib import MatplotlibDeprecationWarning as MDeprecation + import matplotlib.artist as martist from matplotlib.artist import allow_rasterization import matplotlib.axis as maxis @@ -1051,7 +1053,7 @@ def set_aspect(self, aspect, adjustable=None, anchor=None): the option 'normal' for aspect is deprecated. Use 'auto' instead. """ if aspect == 'normal': - raise DeprecationWarning("Use 'auto' instead of 'normal' for " + raise MDeprecation("Use 'auto' instead of 'normal' for " "aspect. Will be removed in 1.4.x") self._aspect = 'auto' From 94d6b422523eec7a4f4616954140cbeab202debd Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Mon, 7 Jan 2013 15:44:08 +0100 Subject: [PATCH 3/4] Replaced DeprecationWarnings with mplDeprecation warnigns --- lib/matplotlib/axes.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index d0ecd08e4ea2..a8f9778aadec 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -10,8 +10,6 @@ import matplotlib rcParams = matplotlib.rcParams -from matplotlib import MatplotlibDeprecationWarning as MDeprecation - import matplotlib.artist as martist from matplotlib.artist import allow_rasterization import matplotlib.axis as maxis @@ -1053,8 +1051,8 @@ def set_aspect(self, aspect, adjustable=None, anchor=None): the option 'normal' for aspect is deprecated. Use 'auto' instead. """ if aspect == 'normal': - raise MDeprecation("Use 'auto' instead of 'normal' for " - "aspect. Will be removed in 1.4.x") + warnings.warn("Use 'auto' instead of 'normal' for aspect. Will " + "be removed in 1.4.x", mplDeprecation) self._aspect = 'auto' elif aspect in ('equal', 'auto'): @@ -7264,8 +7262,8 @@ def pcolor(self, *args, **kwargs): vmin = kwargs.pop('vmin', None) vmax = kwargs.pop('vmax', None) if 'shading' in kwargs: - raise DeprecationWarning("Use edgecolors instead of shading. " - "Will be removed in 1.4") + warnings.warn("Use edgecolors instead of shading. " + "Will be removed in 1.4", mplDeprecation) shading = kwargs.pop('shading', 'flat') X, Y, C = self._pcolorargs('pcolor', *args) @@ -7310,7 +7308,6 @@ def pcolor(self, *args, **kwargs): kwargs['linewidths'] = kwargs.pop('linewidth') kwargs.setdefault('linewidths', linewidths) - if shading == 'faceted': edgecolors = 'k', else: @@ -7320,7 +7317,6 @@ def pcolor(self, *args, **kwargs): kwargs['edgecolors'] = kwargs.pop('edgecolor') ec = kwargs.setdefault('edgecolors', edgecolors) - # aa setting will default via collections to patch.antialiased # unless the boundary is not stroked, in which case the # default will be False; with unstroked boundaries, aa From 107530d38c8c916d051b5789065fb4e185e0aff4 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Wed, 16 Jan 2013 17:39:59 +0100 Subject: [PATCH 4/4] FIX in the scatter method of axes, edgecolors needs to be fetch from the kwargs --- lib/matplotlib/axes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index a8f9778aadec..11b50caf79b9 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -4417,7 +4417,8 @@ def legend(self, *args, **kwargs): instance. If *prop* is a dictionary, a new instance will be created with *prop*. If *None*, use rc settings. - *fontsize*: [ size in points | 'xx-small' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' | 'xx-large' ] + *fontsize*: [size in points | 'xx-small' | 'x-small' | 'small' | + 'medium' | 'large' | 'x-large' | 'xx-large'] Set the font size. May be either a size string, relative to the default font size, or an absolute font size in points. This argument is only used if prop is not specified. @@ -5439,7 +5440,6 @@ def xywhere(xs, ys, mask): if 'zorder' in kwargs: plot_kw['zorder'] = kwargs['zorder'] - if xerr is not None: if (iterable(xerr) and len(xerr) == 2 and iterable(xerr[0]) and iterable(xerr[1])): @@ -6036,6 +6036,7 @@ def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None, colors = mcolors.colorConverter.to_rgba_array(c, alpha) faceted = kwargs.pop('faceted', None) + edgecolors = kwargs.get('edgecolors', None) if faceted is not None: warnings.warn("The faceted option is deprecated. " "Please use edgecolor instead. Will " @@ -6557,9 +6558,10 @@ def arrow(self, x, y, dx, dy, **kwargs): Draws arrow on specified axis from (*x*, *y*) to (*x* + *dx*, *y* + *dy*). Uses FancyArrow patch to construct the arrow. - The resulting arrow is affected by the axes aspect ratio and limits. This - may produce an arrow whose head is not square with its stem. To create - an arrow whose head is square with its stem, use :meth:`annotate`. + The resulting arrow is affected by the axes aspect ratio and limits. + This may produce an arrow whose head is not square with its stem. To + create an arrow whose head is square with its stem, use + :meth:`annotate`. Optional kwargs control the arrow construction and properties: