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

Skip to content

Commit 7fe7500

Browse files
committed
Examples of parameter renames.
1 parent d6ae4ca commit 7fe7500

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Changes in parameter names
2+
``````````````````````````
3+
4+
- The ``arg`` argument to `matplotlib.use` has been renamed to ``backend``.
5+
- The ``normed`` argument to `Axes.hist2d` has been renamed to ``density``.
6+
- The ``s`` argument to `Annotation` (and indirectly `Axes.annotation`) has
7+
been renamed to ``text``.
8+
9+
In each case, the old argument name remains supported (it cannot be used
10+
simultaneously with the new name), but suppport for it will be dropped in
11+
Matplotlib 3.3.

lib/matplotlib/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,13 +1171,14 @@ def __exit__(self, exc_type, exc_value, exc_tb):
11711171
self.__fallback()
11721172

11731173

1174-
def use(arg, warn=False, force=True):
1174+
@cbook._rename_parameter("3.1", "arg", "backend")
1175+
def use(backend, warn=False, force=True):
11751176
"""
11761177
Set the matplotlib backend to one of the known backends.
11771178
11781179
Parameters
11791180
----------
1180-
arg : str
1181+
backend : str
11811182
The backend to switch to. This can either be one of the
11821183
'standard' backend names:
11831184
@@ -1193,6 +1194,8 @@ def use(arg, warn=False, force=True):
11931194
11941195
Note: Standard backend names are case-insensitive here.
11951196
1197+
*arg* is a deprecated synonym for this parameter.
1198+
11961199
warn : bool, optional
11971200
If True, warn if this is called after pyplot has been imported
11981201
and a backend is set up.
@@ -1209,7 +1212,7 @@ def use(arg, warn=False, force=True):
12091212
:ref:`backends`
12101213
matplotlib.get_backend
12111214
"""
1212-
name = validate_backend(arg)
1215+
name = validate_backend(backend)
12131216

12141217
# if setting back to the same thing, do nothing
12151218
if (dict.__getitem__(rcParams, 'backend') == name):

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6871,7 +6871,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
68716871
return tops, bins, cbook.silent_list('Lists of Patches', patches)
68726872

68736873
@_preprocess_data(replace_names=["x", "y", "weights"])
6874-
def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
6874+
@cbook._rename_parameter("3.1", "normed", "density")
6875+
def hist2d(self, x, y, bins=10, range=None, density=False, weights=None,
68756876
cmin=None, cmax=None, **kwargs):
68766877
"""
68776878
Make a 2D histogram plot.
@@ -6905,8 +6906,9 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
69056906
xmax], [ymin, ymax]]``. All values outside of this range will be
69066907
considered outliers and not tallied in the histogram.
69076908
6908-
normed : bool, optional, default: False
6909-
Normalize histogram.
6909+
density : bool, optional, default: False
6910+
Normalize histogram. *normed* is a deprecated synonym for this
6911+
parameter.
69106912
69116913
weights : array_like, shape (n, ), optional, default: None
69126914
An array of values w_i weighing each sample (x_i, y_i).
@@ -6965,7 +6967,7 @@ def hist2d(self, x, y, bins=10, range=None, normed=False, weights=None,
69656967
"""
69666968

69676969
h, xedges, yedges = np.histogram2d(x, y, bins=bins, range=range,
6968-
normed=normed, weights=weights)
6970+
normed=density, weights=weights)
69696971

69706972
if cmin is not None:
69716973
h[h < cmin] = None

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2631,12 +2631,12 @@ def hist(
26312631
# Autogenerated by boilerplate.py. Do not edit as changes will be lost.
26322632
@_autogen_docstring(Axes.hist2d)
26332633
def hist2d(
2634-
x, y, bins=10, range=None, normed=False, weights=None,
2634+
x, y, bins=10, range=None, density=False, weights=None,
26352635
cmin=None, cmax=None, *, data=None, **kwargs):
26362636
__ret = gca().hist2d(
2637-
x, y, bins=bins, range=range, normed=normed, weights=weights,
2638-
cmin=cmin, cmax=cmax, **({"data": data} if data is not None
2639-
else {}), **kwargs)
2637+
x, y, bins=bins, range=range, density=density,
2638+
weights=weights, cmin=cmin, cmax=cmax, **({"data": data} if
2639+
data is not None else {}), **kwargs)
26402640
sci(__ret[-1])
26412641
return __ret
26422642

lib/matplotlib/text.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,15 +1977,16 @@ class Annotation(Text, _AnnotationBase):
19771977
def __str__(self):
19781978
return "Annotation(%g, %g, %r)" % (self.xy[0], self.xy[1], self._text)
19791979

1980-
def __init__(self, s, xy,
1980+
@cbook._rename_parameter("3.1", "s", "text")
1981+
def __init__(self, text, xy,
19811982
xytext=None,
19821983
xycoords='data',
19831984
textcoords=None,
19841985
arrowprops=None,
19851986
annotation_clip=None,
19861987
**kwargs):
19871988
"""
1988-
Annotate the point *xy* with text *s*.
1989+
Annotate the point *xy* with text *text*.
19891990
19901991
In the simplest form, the text is placed at *xy*.
19911992
@@ -1995,8 +1996,9 @@ def __init__(self, s, xy,
19951996
19961997
Parameters
19971998
----------
1998-
s : str
1999-
The text of the annotation.
1999+
text : str
2000+
The text of the annotation. *s* is a deprecated synonym for this
2001+
parameter.
20002002
20012003
xy : (float, float)
20022004
The point *(x,y)* to annotate.
@@ -2171,7 +2173,7 @@ def transform(renderer) -> Transform
21712173
xytext = self.xy
21722174
x, y = xytext
21732175

2174-
Text.__init__(self, x, y, s, **kwargs)
2176+
Text.__init__(self, x, y, text, **kwargs)
21752177

21762178
self.arrowprops = arrowprops
21772179

0 commit comments

Comments
 (0)