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

Skip to content

Commit 25ca8d2

Browse files
authored
Merge pull request #20447 from QuLogic/remove-figax-deprecations
Remove Figure/Axes/Axis deprecations from 3.3
2 parents 6014058 + 740fc3d commit 25ca8d2

File tree

15 files changed

+138
-187
lines changed

15 files changed

+138
-187
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
``figure.add_axes()`` without arguments
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Calling ``fig.add_axes()`` with no arguments will raise an error. Adding a
4+
free-floating axes needs a position rectangle. If you want a figure-filling
5+
single axes, use ``add_subplot()`` instead.
6+
7+
All parameters of `.Figure.subplots` except *nrows* and *ncols* are now keyword-only
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
This avoids typing e.g. ``subplots(1, 1, 1)`` when meaning ``subplot(1, 1, 1)``,
10+
but actually getting ``subplots(1, 1, sharex=1)``.
11+
12+
``add_subplot()`` validates its inputs
13+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14+
In particular, for ``add_subplot(rows, cols, index)``, all parameters must
15+
be integral. Previously strings and floats were accepted and converted to
16+
int.
17+
18+
``SubplotSpec.get_rows_columns``
19+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20+
Use the ``GridSpec.nrows``, ``GridSpec.ncols``, ``SubplotSpec.rowspan``, and
21+
``SubplotSpec.colspan`` properties instead.
22+
23+
``autofmt_xdate(which=None)``
24+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
Use its more explicit synonym, ``which="major"``, instead.
26+
27+
`.pyplot.tight_layout` parameters are now keyword-only
28+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29+
All parameters of `.pyplot.tight_layout` are now keyword-only, to be consistent
30+
with `.Figure.tight_layout`.
31+
32+
Parameters *norm* and *vmin*/*vmax* may not be used simultaneously
33+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
Passing parameters *norm* and *vmin*/*vmax* simultaneously to functions using
35+
colormapping such as ``scatter()`` and ``imshow()`` is no longer supported.
36+
Instead of ``norm=LogNorm(), vmin=min_val, vmax=max_val`` pass
37+
``norm=LogNorm(min_val, max_val)``. *vmin* and *vmax* should only be used
38+
without setting *norm*.
39+
40+
`.Axes.annotate` and `.pyplot.annotate` parameter name changed
41+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42+
The parameter *s* to `.Axes.annotate` and `.pyplot.annotate` has previously
43+
been renamed to *text*, matching `.Annotation`. The old parameter name is no
44+
longer supported.
45+
46+
*orientation* of ``eventplot()`` and `.EventCollection`
47+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
48+
Setting the *orientation* of an ``eventplot()`` or `.EventCollection` to "none"
49+
or None is no longer supported; set it to "horizontal" instead. Moreover, the two
50+
orientations ("horizontal" and "vertical") are now case-sensitive.
51+
52+
``ContourSet.ax``, ``Quiver.ax``
53+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
54+
These attributes have been removed in favor of ``ContourSet.axes`` and
55+
``Quiver.axes``, for consistency with other artists.
56+
57+
*fontdict* and *minor* parameters of `.Axes.set_xticklabels` / `.Axes.set_yticklabels` are now keyword-only
58+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

doc/api/prev_api_changes/api_changes_3.3.0/deprecations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Parameters *norm* and *vmin*/*vmax* should not be used simultaneously
9393
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9494
Passing parameters *norm* and *vmin*/*vmax* simultaneously to functions using
9595
colormapping such as ``scatter()`` and ``imshow()`` is deprecated.
96-
Inestead of ``norm=LogNorm(), vmin=min_val, vmax=max_val`` pass
96+
Instead of ``norm=LogNorm(), vmin=min_val, vmax=max_val`` pass
9797
``norm=LogNorm(min_val, max_val)``. *vmin* and *vmax* should only be used
9898
without setting *norm*.
9999

lib/matplotlib/axes/_axes.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,6 @@ def text(self, x, y, s, fontdict=None, **kwargs):
661661
self._add_text(t)
662662
return t
663663

664-
@_api.rename_parameter("3.3", "s", "text")
665664
@docstring.dedent_interpd
666665
def annotate(self, text, xy, *args, **kwargs):
667666
a = mtext.Annotation(text, xy, *args, **kwargs)
@@ -1367,10 +1366,9 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
13671366
minline = (lineoffsets - linelengths).min()
13681367
maxline = (lineoffsets + linelengths).max()
13691368

1370-
if (orientation is not None and
1371-
orientation.lower() == "vertical"):
1369+
if orientation == "vertical":
13721370
corners = (minline, minpos), (maxline, maxpos)
1373-
else: # "horizontal", None or "none" (see EventCollection)
1371+
else: # "horizontal"
13741372
corners = (minpos, minline), (maxpos, maxline)
13751373
self.update_datalim(corners)
13761374
self._request_autoscale_view()
@@ -4399,7 +4397,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
43994397
*vmin* and *vmax* are used in conjunction with the default norm to
44004398
map the color array *c* to the colormap *cmap*. If None, the
44014399
respective min and max of the color array is used.
4402-
It is deprecated to use *vmin*/*vmax* when *norm* is given.
4400+
It is an error to use *vmin*/*vmax* when *norm* is given.
44034401
44044402
alpha : float, default: None
44054403
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -4690,7 +4688,7 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
46904688
automatically chosen by the `.Normalize` instance (defaults to
46914689
the respective min/max values of the bins in case of the default
46924690
linear scaling).
4693-
It is deprecated to use *vmin*/*vmax* when *norm* is given.
4691+
It is an error to use *vmin*/*vmax* when *norm* is given.
46944692
46954693
alpha : float between 0 and 1, optional
46964694
The alpha blending value, between 0 (transparent) and 1 (opaque).
@@ -5487,7 +5485,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
54875485
When using scalar data and no explicit *norm*, *vmin* and *vmax*
54885486
define the data range that the colormap covers. By default,
54895487
the colormap covers the complete value range of the supplied
5490-
data. It is deprecated to use *vmin*/*vmax* when *norm* is given.
5488+
data. It is an error to use *vmin*/*vmax* when *norm* is given.
54915489
When using RGB(A) data, parameters *vmin*/*vmax* are ignored.
54925490
54935491
origin : {'upper', 'lower'}, default: :rc:`image.origin`
@@ -5809,7 +5807,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
58095807
automatically chosen by the `.Normalize` instance (defaults to
58105808
the respective min/max values of *C* in case of the default linear
58115809
scaling).
5812-
It is deprecated to use *vmin*/*vmax* when *norm* is given.
5810+
It is an error to use *vmin*/*vmax* when *norm* is given.
58135811
58145812
edgecolors : {'none', None, 'face', color, color sequence}, optional
58155813
The color of the edges. Defaults to 'none'. Possible values:
@@ -6039,7 +6037,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
60396037
automatically chosen by the `.Normalize` instance (defaults to
60406038
the respective min/max values of *C* in case of the default linear
60416039
scaling).
6042-
It is deprecated to use *vmin*/*vmax* when *norm* is given.
6040+
It is an error to use *vmin*/*vmax* when *norm* is given.
60436041
60446042
edgecolors : {'none', None, 'face', color, color sequence}, optional
60456043
The color of the edges. Defaults to 'none'. Possible values:
@@ -6290,7 +6288,7 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62906288
automatically chosen by the `.Normalize` instance (defaults to
62916289
the respective min/max values of *C* in case of the default linear
62926290
scaling).
6293-
It is deprecated to use *vmin*/*vmax* when *norm* is given.
6291+
It is an error to use *vmin*/*vmax* when *norm* is given.
62946292
62956293
alpha : float, default: None
62966294
The alpha blending value, between 0 (transparent) and 1 (opaque).

lib/matplotlib/axis.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,8 +1287,7 @@ def get_minorticklocs(self):
12871287
if ~np.isclose(tr_loc, tr_major_locs, atol=tol, rtol=0).any()]
12881288
return minor_locs
12891289

1290-
@_api.make_keyword_only("3.3", "minor")
1291-
def get_ticklocs(self, minor=False):
1290+
def get_ticklocs(self, *, minor=False):
12921291
"""Return this Axis' tick locations in data coordinates."""
12931292
return self.get_minorticklocs() if minor else self.get_majorticklocs()
12941293

@@ -1755,8 +1754,7 @@ def set_ticklabels(self, ticklabels, *, minor=False, **kwargs):
17551754

17561755
# Wrapper around set_ticklabels used to generate Axes.set_x/ytickabels; can
17571756
# go away once the API of Axes.set_x/yticklabels becomes consistent.
1758-
@_api.make_keyword_only("3.3", "fontdict")
1759-
def _set_ticklabels(self, labels, fontdict=None, minor=False, **kwargs):
1757+
def _set_ticklabels(self, labels, *, fontdict=None, minor=False, **kwargs):
17601758
"""
17611759
Set this Axis' labels with list of string labels.
17621760

lib/matplotlib/cm.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,10 @@ def _scale_norm(self, norm, vmin, vmax):
278278
if vmin is not None or vmax is not None:
279279
self.set_clim(vmin, vmax)
280280
if norm is not None:
281-
_api.warn_deprecated(
282-
"3.3",
283-
message="Passing parameters norm and vmin/vmax "
284-
"simultaneously is deprecated since %(since)s and "
285-
"will become an error %(removal)s. Please pass "
286-
"vmin/vmax directly to the norm when creating it.")
281+
raise ValueError(
282+
"Passing parameters norm and vmin/vmax simultaneously is "
283+
"not supported. Please pass vmin/vmax directly to the "
284+
"norm when creating it.")
287285

288286
# always resolve the autoscaling so we have concrete limits
289287
# rather than deferring to draw time.

lib/matplotlib/collections.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,32 +1634,17 @@ def switch_orientation(self):
16341634
self._is_horizontal = not self.is_horizontal()
16351635
self.stale = True
16361636

1637-
def set_orientation(self, orientation=None):
1637+
def set_orientation(self, orientation):
16381638
"""
16391639
Set the orientation of the event line.
16401640
16411641
Parameters
16421642
----------
16431643
orientation : {'horizontal', 'vertical'}
16441644
"""
1645-
try:
1646-
is_horizontal = _api.check_getitem(
1647-
{"horizontal": True, "vertical": False},
1648-
orientation=orientation)
1649-
except ValueError:
1650-
if (orientation is None or orientation.lower() == "none"
1651-
or orientation.lower() == "horizontal"):
1652-
is_horizontal = True
1653-
elif orientation.lower() == "vertical":
1654-
is_horizontal = False
1655-
else:
1656-
raise
1657-
normalized = "horizontal" if is_horizontal else "vertical"
1658-
_api.warn_deprecated(
1659-
"3.3", message="Support for setting the orientation of "
1660-
f"EventCollection to {orientation!r} is deprecated since "
1661-
f"%(since)s and will be removed %(removal)s; please set it to "
1662-
f"{normalized!r} instead.")
1645+
is_horizontal = _api.check_getitem(
1646+
{"horizontal": True, "vertical": False},
1647+
orientation=orientation)
16631648
if is_horizontal == self.is_horizontal():
16641649
return
16651650
self.switch_orientation()

lib/matplotlib/contour.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,6 @@ class ContourSet(cm.ScalarMappable, ContourLabeler):
720720
%(contour_set_attributes)s
721721
"""
722722

723-
ax = _api.deprecated("3.3")(property(lambda self: self.axes))
724-
725723
def __init__(self, ax, *args,
726724
levels=None, filled=False, linewidths=None, linestyles=None,
727725
hatches=(None,), alpha=None, origin=None, extent=None,

lib/matplotlib/figure.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,7 @@ def autofmt_xdate(
271271
which : {'major', 'minor', 'both'}, default: 'major'
272272
Selects which ticklabels to rotate.
273273
"""
274-
if which is None:
275-
_api.warn_deprecated(
276-
"3.3", message="Support for passing which=None to mean "
277-
"which='major' is deprecated since %(since)s and will be "
278-
"removed %(removal)s.")
274+
_api.check_in_list(['major', 'minor', 'both'], which=which)
279275
allsubplots = all(hasattr(ax, 'get_subplotspec') for ax in self.axes)
280276
if len(self.axes) == 1:
281277
for label in self.axes[0].get_xticklabels(which=which):
@@ -622,12 +618,8 @@ def add_axes(self, *args, **kwargs):
622618
"""
623619

624620
if not len(args) and 'rect' not in kwargs:
625-
_api.warn_deprecated(
626-
"3.3",
627-
message="Calling add_axes() without argument is "
628-
"deprecated since %(since)s and will be removed %(removal)s. "
629-
"You may want to use add_subplot() instead.")
630-
return
621+
raise TypeError(
622+
"add_axes() missing 1 required positional argument: 'rect'")
631623
elif 'rect' in kwargs:
632624
if len(args):
633625
raise TypeError(
@@ -795,8 +787,7 @@ def _add_axes_internal(self, ax, key):
795787
ax.stale_callback = _stale_figure_callback
796788
return ax
797789

798-
@_api.make_keyword_only("3.3", "sharex")
799-
def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
790+
def subplots(self, nrows=1, ncols=1, *, sharex=False, sharey=False,
800791
squeeze=True, subplot_kw=None, gridspec_kw=None):
801792
"""
802793
Add a set of subplots to this figure.

lib/matplotlib/gridspec.py

Lines changed: 23 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ def __init__(self, nrows, ncols, height_ratios=None, width_ratios=None):
4747
"""
4848
if not isinstance(nrows, Integral) or nrows <= 0:
4949
raise ValueError(
50-
f"Number of rows must be a positive integer, not {nrows}")
50+
f"Number of rows must be a positive integer, not {nrows!r}")
5151
if not isinstance(ncols, Integral) or ncols <= 0:
5252
raise ValueError(
53-
f"Number of columns must be a positive integer, not {ncols}")
53+
f"Number of columns must be a positive integer, not {ncols!r}")
5454
self._nrows, self._ncols = nrows, ncols
5555
self.set_height_ratios(height_ratios)
5656
self.set_width_ratios(width_ratios)
@@ -604,51 +604,40 @@ def _from_subplot_args(figure, args):
604604
- a `.SubplotSpec` -- returned as is;
605605
- one or three numbers -- a MATLAB-style subplot specifier.
606606
"""
607-
message = ("Passing non-integers as three-element position "
608-
"specification is deprecated since %(since)s and will be "
609-
"removed %(removal)s.")
610607
if len(args) == 1:
611608
arg, = args
612609
if isinstance(arg, SubplotSpec):
613610
return arg
614-
else:
615-
if not isinstance(arg, Integral):
616-
_api.warn_deprecated("3.3", message=message)
617-
arg = str(arg)
618-
try:
619-
rows, cols, num = map(int, str(arg))
620-
except ValueError:
621-
raise ValueError(
622-
f"Single argument to subplot must be a three-digit "
623-
f"integer, not {arg}") from None
624-
i = j = num
611+
elif not isinstance(arg, Integral):
612+
raise ValueError(
613+
f"Single argument to subplot must be a three-digit "
614+
f"integer, not {arg!r}")
615+
try:
616+
rows, cols, num = map(int, str(arg))
617+
except ValueError:
618+
raise ValueError(
619+
f"Single argument to subplot must be a three-digit "
620+
f"integer, not {arg!r}") from None
625621
elif len(args) == 3:
626622
rows, cols, num = args
627-
if not (isinstance(rows, Integral) and isinstance(cols, Integral)):
628-
_api.warn_deprecated("3.3", message=message)
629-
rows, cols = map(int, [rows, cols])
630-
gs = GridSpec(rows, cols, figure=figure)
631-
if isinstance(num, tuple) and len(num) == 2:
632-
if not all(isinstance(n, Integral) for n in num):
633-
_api.warn_deprecated("3.3", message=message)
634-
i, j = map(int, num)
635-
else:
636-
i, j = num
637-
else:
638-
if not isinstance(num, Integral):
639-
_api.warn_deprecated("3.3", message=message)
640-
num = int(num)
641-
if num < 1 or num > rows*cols:
642-
raise ValueError(
643-
f"num must be 1 <= num <= {rows*cols}, not {num}")
644-
i = j = num
645623
else:
646624
raise TypeError(f"subplot() takes 1 or 3 positional arguments but "
647625
f"{len(args)} were given")
648626

649627
gs = GridSpec._check_gridspec_exists(figure, rows, cols)
650628
if gs is None:
651629
gs = GridSpec(rows, cols, figure=figure)
630+
if isinstance(num, tuple) and len(num) == 2:
631+
if not all(isinstance(n, Integral) for n in num):
632+
raise ValueError(
633+
f"Subplot specifier tuple must contain integers, not {num}"
634+
)
635+
i, j = num
636+
else:
637+
if not isinstance(num, Integral) or num < 1 or num > rows*cols:
638+
raise ValueError(
639+
f"num must be 1 <= num <= {rows*cols}, not {num!r}")
640+
i = j = num
652641
return gs[i-1:j]
653642

654643
# num2 is a property only to handle the case where it is None and someone
@@ -679,18 +668,6 @@ def get_geometry(self):
679668
rows, cols = self.get_gridspec().get_geometry()
680669
return rows, cols, self.num1, self.num2
681670

682-
@_api.deprecated("3.3", alternative="rowspan, colspan")
683-
def get_rows_columns(self):
684-
"""
685-
Return the subplot row and column numbers as a tuple
686-
``(n_rows, n_cols, row_start, row_stop, col_start, col_stop)``.
687-
"""
688-
gridspec = self.get_gridspec()
689-
nrows, ncols = gridspec.get_geometry()
690-
row_start, col_start = divmod(self.num1, ncols)
691-
row_stop, col_stop = divmod(self.num2, ncols)
692-
return nrows, ncols, row_start, row_stop, col_start, col_stop
693-
694671
@property
695672
def rowspan(self):
696673
"""The rows spanned by this subplot, as a `range` object."""

0 commit comments

Comments
 (0)