From 6be9c9f5f29cea02940014e4b107de4382785d0a Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sat, 28 Apr 2018 00:11:00 +1000 Subject: [PATCH 1/4] Use named args for xticks, yticks in pyplot --- lib/matplotlib/pyplot.py | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 8a32370f2ab1..b06801ce7cbd 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -1365,7 +1365,7 @@ def ylim(*args, **kwargs): return ret -def xticks(*args, **kwargs): +def xticks(ticks=None, labels=None, **kwargs): """ Get or set the current tick locations and labels of the x-axis. @@ -1373,11 +1373,11 @@ def xticks(*args, **kwargs): locs, labels = xticks() # Get locations and labels - xticks(locs, [labels], **kwargs) # Set locations and labels + xticks(ticks, [labels], **kwargs) # Set locations and labels Parameters ---------- - locs : array_like + ticks : array_like A list of positions at which ticks should be placed. You can pass an empty list to disable xticks. @@ -1427,24 +1427,22 @@ def xticks(*args, **kwargs): """ ax = gca() - if len(args) == 0: + if ticks is None and labels is None: locs = ax.get_xticks() labels = ax.get_xticklabels() - elif len(args) == 1: - locs = ax.set_xticks(args[0]) + elif labels is None: + locs = ax.set_xticks(ticks) labels = ax.get_xticklabels() - elif len(args) == 2: - locs = ax.set_xticks(args[0]) - labels = ax.set_xticklabels(args[1], **kwargs) else: - raise TypeError('Illegal number of arguments to xticks') + locs = ax.set_xticks(ticks) + labels = ax.set_xticklabels(labels, **kwargs) for l in labels: l.update(kwargs) return locs, silent_list('Text xticklabel', labels) -def yticks(*args, **kwargs): +def yticks(ticks=None, labels=None, **kwargs): """ Get or set the current tick locations and labels of the y-axis. @@ -1452,11 +1450,11 @@ def yticks(*args, **kwargs): locs, labels = yticks() # Get locations and labels - yticks(locs, [labels], **kwargs) # Set locations and labels + yticks(ticks, [labels], **kwargs) # Set locations and labels Parameters ---------- - locs : array_like + ticks : array_like A list of positions at which ticks should be placed. You can pass an empty list to disable yticks. @@ -1506,17 +1504,15 @@ def yticks(*args, **kwargs): """ ax = gca() - if len(args) == 0: + if ticks is None and labels is None: locs = ax.get_yticks() labels = ax.get_yticklabels() - elif len(args) == 1: - locs = ax.set_yticks(args[0]) + elif labels is None: + locs = ax.set_yticks(ticks) labels = ax.get_yticklabels() - elif len(args) == 2: - locs = ax.set_yticks(args[0]) - labels = ax.set_yticklabels(args[1], **kwargs) else: - raise TypeError('Illegal number of arguments to yticks') + locs = ax.set_yticks(ticks) + labels = ax.set_yticklabels(labels, **kwargs) for l in labels: l.update(kwargs) From 09991e6cab0b33964021ce962309c9b865d98d20 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sat, 28 Apr 2018 01:23:13 +1000 Subject: [PATCH 2/4] Clarify and check alternative names for axis limits --- doc/api/next_api_changes/2018-04-22-ZHD.rst | 10 +++ lib/matplotlib/axes/_base.py | 68 +++++++++++++-------- lib/mpl_toolkits/mplot3d/axes3d.py | 66 ++++++++++++-------- 3 files changed, 96 insertions(+), 48 deletions(-) create mode 100644 doc/api/next_api_changes/2018-04-22-ZHD.rst diff --git a/doc/api/next_api_changes/2018-04-22-ZHD.rst b/doc/api/next_api_changes/2018-04-22-ZHD.rst new file mode 100644 index 000000000000..e069f2f00bde --- /dev/null +++ b/doc/api/next_api_changes/2018-04-22-ZHD.rst @@ -0,0 +1,10 @@ +Different exception types for undocumented options +-------------------------------------------------- + +- Passing the undocumented ``xmin`` or ``xmax`` arguments to + :meth:`~matplotlib.axes.Axes.set_xlim` would silently override the ``left`` + and ``right`` arguments. :meth:`~matplotlib.axes.Axes.set_ylim` and the + 3D equivalents (e.g. :meth:`~mpl_toolkits.axes.Axes3D.set_zlim3d`) had a + corresponding problem. + The ``_min`` and ``_max`` arguments are now deprecated, and a ``TypeError`` + will be raised if they would override the earlier limit arguments. diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e50e129ecb3e..19762e83bf2b 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3028,7 +3028,8 @@ def _validate_converted_limits(self, limit, convert): raise ValueError("Axis limits cannot be NaN or Inf") return converted_limit - def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw): + def set_xlim(self, left=None, right=None, emit=True, auto=False, + *, xmin=None, xmax=None): """ Set the data limits for the x-axis @@ -3039,6 +3040,9 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw): left : scalar, optional The left xlim (default: None, which leaves the left limit unchanged). + The left and right xlims may be passed as the tuple + (`left`, `right`) as the first positional argument (or as + the `left` keyword argument). right : scalar, optional The right xlim (default: None, which leaves the right limit @@ -3051,10 +3055,11 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw): Whether to turn on autoscaling of the x-axis. True turns on, False turns off (default action), None leaves unchanged. - xlimits : tuple, optional - The left and right xlims may be passed as the tuple - (`left`, `right`) as the first positional argument (or as - the `left` keyword argument). + xmin, xmax : scalar, optional + These arguments are deprecated and will be removed in a future + version. They are equivalent to left and right respectively, + and it is an error to pass both `xmin` and `left` or + `xmax` and `right`. Returns ------- @@ -3085,15 +3090,20 @@ def set_xlim(self, left=None, right=None, emit=True, auto=False, **kw): >>> set_xlim(5000, 0) """ - if 'xmin' in kw: - left = kw.pop('xmin') - if 'xmax' in kw: - right = kw.pop('xmax') - if kw: - raise ValueError("unrecognized kwargs: %s" % list(kw)) - if right is None and iterable(left): left, right = left + if xmin is not None: + cbook.warn_deprecated('3.0', name='`xmin`', + alternative='`left`', obj_type='argument') + if left is not None: + raise TypeError('Cannot pass both `xmin` and `left`') + left = xmin + if xmax is not None: + cbook.warn_deprecated('3.0', name='`xmax`', + alternative='`right`', obj_type='argument') + if right is not None: + raise TypeError('Cannot pass both `xmax` and `right`') + right = xmax self._process_unit_info(xdata=(left, right)) left = self._validate_converted_limits(left, self.convert_xunits) @@ -3358,7 +3368,8 @@ def get_ylim(self): """ return tuple(self.viewLim.intervaly) - def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw): + def set_ylim(self, bottom=None, top=None, emit=True, auto=False, + *, ymin=None, ymax=None): """ Set the data limits for the y-axis @@ -3369,6 +3380,9 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw): bottom : scalar, optional The bottom ylim (default: None, which leaves the bottom limit unchanged). + The bottom and top ylims may be passed as the tuple + (`bottom`, `top`) as the first positional argument (or as + the `bottom` keyword argument). top : scalar, optional The top ylim (default: None, which leaves the top limit @@ -3381,10 +3395,11 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw): Whether to turn on autoscaling of the y-axis. True turns on, False turns off (default action), None leaves unchanged. - ylimits : tuple, optional - The bottom and top yxlims may be passed as the tuple - (`bottom`, `top`) as the first positional argument (or as - the `bottom` keyword argument). + ymin, ymax : scalar, optional + These arguments are deprecated and will be removed in a future + version. They are equivalent to bottom and top respectively, + and it is an error to pass both `xmin` and `bottom` or + `xmax` and `top`. Returns ------- @@ -3414,15 +3429,20 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False, **kw): >>> set_ylim(5000, 0) """ - if 'ymin' in kw: - bottom = kw.pop('ymin') - if 'ymax' in kw: - top = kw.pop('ymax') - if kw: - raise ValueError("unrecognized kwargs: %s" % list(kw)) - if top is None and iterable(bottom): bottom, top = bottom + if ymin is not None: + cbook.warn_deprecated('3.0', name='`ymin`', + alternative='`bottom`', obj_type='argument') + if bottom is not None: + raise TypeError('Cannot pass both `ymin` and `bottom`') + bottom = ymin + if ymax is not None: + cbook.warn_deprecated('3.0', name='`ymax`', + alternative='`top`', obj_type='argument') + if top is not None: + raise TypeError('Cannot pass both `ymax` and `top`') + top = ymax bottom = self._validate_converted_limits(bottom, self.convert_yunits) top = self._validate_converted_limits(top, self.convert_yunits) diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index 1c186aae7a98..aaf19637be9f 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -603,22 +603,28 @@ def _determine_lims(self, xmin=None, xmax=None, *args, **kwargs): xmax += 0.05 return (xmin, xmax) - def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw): + def set_xlim3d(self, left=None, right=None, emit=True, auto=False, + *, xmin=None, xmax=None): """ Set 3D x limits. See :meth:`matplotlib.axes.Axes.set_xlim` for full documentation. """ - if 'xmin' in kw: - left = kw.pop('xmin') - if 'xmax' in kw: - right = kw.pop('xmax') - if kw: - raise ValueError("unrecognized kwargs: %s" % list(kw)) - if right is None and cbook.iterable(left): left, right = left + if xmin is not None: + cbook.warn_deprecated('3.0', name='`xmin`', + alternative='`left`', obj_type='argument') + if left is not None: + raise TypeError('Cannot pass both `xmin` and `left`') + left = xmin + if xmax is not None: + cbook.warn_deprecated('3.0', name='`xmax`', + alternative='`right`', obj_type='argument') + if right is not None: + raise TypeError('Cannot pass both `xmax` and `right`') + right = xmax self._process_unit_info(xdata=(left, right)) left = self._validate_converted_limits(left, self.convert_xunits) @@ -655,22 +661,28 @@ def set_xlim3d(self, left=None, right=None, emit=True, auto=False, **kw): return left, right set_xlim = set_xlim3d - def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw): + def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, + *, ymin=None, ymax=None): """ Set 3D y limits. See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation. """ - if 'ymin' in kw: - bottom = kw.pop('ymin') - if 'ymax' in kw: - top = kw.pop('ymax') - if kw: - raise ValueError("unrecognized kwargs: %s" % list(kw)) - if top is None and cbook.iterable(bottom): bottom, top = bottom + if ymin is not None: + cbook.warn_deprecated('3.0', name='`ymin`', + alternative='`bottom`', obj_type='argument') + if bottom is not None: + raise TypeError('Cannot pass both `ymin` and `bottom`') + bottom = ymin + if ymax is not None: + cbook.warn_deprecated('3.0', name='`ymax`', + alternative='`top`', obj_type='argument') + if top is not None: + raise TypeError('Cannot pass both `ymax` and `top`') + top = ymax self._process_unit_info(ydata=(bottom, top)) bottom = self._validate_converted_limits(bottom, self.convert_yunits) @@ -707,22 +719,28 @@ def set_ylim3d(self, bottom=None, top=None, emit=True, auto=False, **kw): return bottom, top set_ylim = set_ylim3d - def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, **kw): + def set_zlim3d(self, bottom=None, top=None, emit=True, auto=False, + *, zmin=None, zmax=None): """ Set 3D z limits. See :meth:`matplotlib.axes.Axes.set_ylim` for full documentation """ - if 'zmin' in kw: - bottom = kw.pop('zmin') - if 'zmax' in kw: - top = kw.pop('zmax') - if kw: - raise ValueError("unrecognized kwargs: %s" % list(kw)) - if top is None and cbook.iterable(bottom): bottom, top = bottom + if zmin is not None: + cbook.warn_deprecated('3.0', name='`zmin`', + alternative='`bottom`', obj_type='argument') + if bottom is not None: + raise TypeError('Cannot pass both `zmin` and `bottom`') + bottom = zmin + if zmax is not None: + cbook.warn_deprecated('3.0', name='`zmax`', + alternative='`top`', obj_type='argument') + if top is not None: + raise TypeError('Cannot pass both `zmax` and `top`') + top = zmax self._process_unit_info(zdata=(bottom, top)) bottom = self._validate_converted_limits(bottom, self.convert_zunits) From 5720387dd5199d174ba601a38d3f38f124e68dea Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sat, 28 Apr 2018 01:27:33 +1000 Subject: [PATCH 3/4] Minor refactor for clarity --- lib/matplotlib/axis.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index 8383e1535983..a659507b9b08 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -334,12 +334,10 @@ def get_view_interval(self): raise NotImplementedError('Derived must override') def _apply_params(self, **kw): - switchkw = ['gridOn', 'tick1On', 'tick2On', 'label1On', 'label2On'] - switches = [k for k in kw if k in switchkw] - for k in switches: - setattr(self, k, kw.pop(k)) - newmarker = [k for k in kw if k in ['size', 'width', 'pad', 'tickdir']] - if newmarker: + for name in ['gridOn', 'tick1On', 'tick2On', 'label1On', 'label2On']: + if name in kw: + setattr(self, name, kw.pop(name)) + if any(k in kw for k in ['size', 'width', 'pad', 'tickdir']): self._size = kw.pop('size', self._size) # Width could be handled outside this block, but it is # convenient to leave it here. From c40839283837366b3fcc4dd537ba62107d5d4cc4 Mon Sep 17 00:00:00 2001 From: Zac-HD Date: Sat, 28 Apr 2018 01:38:11 +1000 Subject: [PATCH 4/4] Eliminate unused variables in axes3d --- doc/api/next_api_changes/2018-04-22-ZHD.rst | 4 ++++ lib/matplotlib/axes/_base.py | 2 -- lib/mpl_toolkits/mplot3d/axes3d.py | 20 ++++---------------- 3 files changed, 8 insertions(+), 18 deletions(-) diff --git a/doc/api/next_api_changes/2018-04-22-ZHD.rst b/doc/api/next_api_changes/2018-04-22-ZHD.rst index e069f2f00bde..9b519ab9e88b 100644 --- a/doc/api/next_api_changes/2018-04-22-ZHD.rst +++ b/doc/api/next_api_changes/2018-04-22-ZHD.rst @@ -1,6 +1,10 @@ Different exception types for undocumented options -------------------------------------------------- +- Passing ``style='comma'`` to :meth:`~matplotlib.axes.Axes.ticklabel_format` + was never supported. It now raises ``ValueError`` like all other + unsupported styles, rather than ``NotImplementedError``. + - Passing the undocumented ``xmin`` or ``xmax`` arguments to :meth:`~matplotlib.axes.Axes.set_xlim` would silently override the ``left`` and ``right`` arguments. :meth:`~matplotlib.axes.Axes.set_ylim` and the diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 19762e83bf2b..a15654a448cb 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2756,8 +2756,6 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None, sb = True elif style == 'plain': sb = False - elif style == 'comma': - raise NotImplementedError("comma style remains to be added") elif style == '': sb = None else: diff --git a/lib/mpl_toolkits/mplot3d/axes3d.py b/lib/mpl_toolkits/mplot3d/axes3d.py index aaf19637be9f..6639cfe941ff 100644 --- a/lib/mpl_toolkits/mplot3d/axes3d.py +++ b/lib/mpl_toolkits/mplot3d/axes3d.py @@ -532,9 +532,7 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True, _tight = self._tight = bool(tight) if scalex and self._autoscaleXon: - xshared = self._shared_x_axes.get_siblings(self) - dl = [ax.dataLim for ax in xshared] - bb = mtransforms.BboxBase.union(dl) + self._shared_x_axes.clean() x0, x1 = self.xy_dataLim.intervalx xlocator = self.xaxis.get_major_locator() try: @@ -551,9 +549,7 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True, self.set_xbound(x0, x1) if scaley and self._autoscaleYon: - yshared = self._shared_y_axes.get_siblings(self) - dl = [ax.dataLim for ax in yshared] - bb = mtransforms.BboxBase.union(dl) + self._shared_y_axes.clean() y0, y1 = self.xy_dataLim.intervaly ylocator = self.yaxis.get_major_locator() try: @@ -570,9 +566,7 @@ def autoscale_view(self, tight=None, scalex=True, scaley=True, self.set_ybound(y0, y1) if scalez and self._autoscaleZon: - zshared = self._shared_z_axes.get_siblings(self) - dl = [ax.dataLim for ax in zshared] - bb = mtransforms.BboxBase.union(dl) + self._shared_z_axes.clean() z0, z1 = self.zz_dataLim.intervalx zlocator = self.zaxis.get_major_locator() try: @@ -1366,13 +1360,8 @@ def ticklabel_format( raise ValueError("scilimits must be a sequence of 2 integers") if style[:3] == 'sci': sb = True - elif style in ['plain', 'comma']: + elif style == 'plain': sb = False - if style == 'plain': - cb = False - else: - cb = True - raise NotImplementedError("comma style remains to be added") elif style == '': sb = None else: @@ -1720,7 +1709,6 @@ def plot_surface(self, X, Y, Z, *args, norm=None, vmin=None, # The construction leaves the array with duplicate points, which # are removed here. ps = list(zip(*ps)) - lastp = np.array([]) ps2 = [ps[0]] + [ps[i] for i in range(1, len(ps)) if ps[i] != ps[i-1]] avgzsum = sum(p[2] for p in ps2) polys.append(ps2) 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