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

Skip to content

Commit 36c348e

Browse files
committed
Deprecate positional use of most arguments of plotting functions
This increases maintainability for developers and disallows bad practice of passing lots of positional arguments for users. If in doubt, I've erred on the side of allowing as much positional arguments as possible as long as the intent of a call is still readable. Note: This was originally motivated by bxp() and boxplot() having many overlapping parameters but differently ordered. While at it, I think it's better to rollout the change to all plotting functions and communicate that in one go rather than having lots of individual change notices over time. Also, the freedom to reorder parameters only sets in after the deprecation. So let's start this now.
1 parent f048468 commit 36c348e

File tree

7 files changed

+61
-28
lines changed

7 files changed

+61
-28
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Positional parameters in plotting functions
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
Many plotting functions will restrict positional arguments to the first few parameters
5+
in the future. All further configuration parameters will have to be passed as keyword
6+
arguments. This is to enforce better code and and allow for future changes with reduced
7+
risk of breaking existing code.

galleries/examples/lines_bars_and_markers/cohere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
axs[0].set_ylabel('s1 and s2')
2828
axs[0].grid(True)
2929

30-
cxy, f = axs[1].cohere(s1, s2, 256, 1. / dt)
30+
cxy, f = axs[1].cohere(s1, s2, NFFT=256, Fs=1. / dt)
3131
axs[1].set_ylabel('Coherence')
3232

3333
plt.show()

galleries/examples/lines_bars_and_markers/csd_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
ax1.set_ylabel('s1 and s2')
3535
ax1.grid(True)
3636

37-
cxy, f = ax2.csd(s1, s2, 256, 1. / dt)
37+
cxy, f = ax2.csd(s1, s2, NFFT=256, Fs=1. / dt)
3838
ax2.set_ylabel('CSD (dB)')
3939

4040
plt.show()

galleries/examples/lines_bars_and_markers/psd_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ax0.plot(t, s)
3131
ax0.set_xlabel('Time (s)')
3232
ax0.set_ylabel('Signal')
33-
ax1.psd(s, 512, 1 / dt)
33+
ax1.psd(s, NFFT=512, Fs=1 / dt)
3434

3535
plt.show()
3636

galleries/examples/statistics/boxplot_demo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@
3434
axs[0, 0].set_title('basic plot')
3535

3636
# notched plot
37-
axs[0, 1].boxplot(data, 1)
37+
axs[0, 1].boxplot(data, notch=True)
3838
axs[0, 1].set_title('notched plot')
3939

4040
# change outlier point symbols
41-
axs[0, 2].boxplot(data, 0, 'gD')
41+
axs[0, 2].boxplot(data, sym='gD')
4242
axs[0, 2].set_title('change outlier\npoint symbols')
4343

4444
# don't show outlier points
45-
axs[1, 0].boxplot(data, 0, '')
45+
axs[1, 0].boxplot(data, sym='')
4646
axs[1, 0].set_title("don't show\noutlier points")
4747

4848
# horizontal boxes
49-
axs[1, 1].boxplot(data, 0, 'rs', 0)
49+
axs[1, 1].boxplot(data, sym='rs', vert=False)
5050
axs[1, 1].set_title('horizontal boxes')
5151

5252
# change whisker length
53-
axs[1, 2].boxplot(data, 0, 'rs', 0, 0.75)
53+
axs[1, 2].boxplot(data, sym='rs', vert=False, whis=0.75)
5454
axs[1, 2].set_title('change whisker length')
5555

5656
fig.subplots_adjust(left=0.08, right=0.98, bottom=0.05, top=0.9,

lib/matplotlib/axes/_axes.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,7 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
10571057
self._request_autoscale_view("x")
10581058
return p
10591059

1060+
@_api.make_keyword_only("3.9", "label")
10601061
@_preprocess_data(replace_names=["y", "xmin", "xmax", "colors"],
10611062
label_namer="y")
10621063
def hlines(self, y, xmin, xmax, colors=None, linestyles='solid',
@@ -1148,6 +1149,7 @@ def hlines(self, y, xmin, xmax, colors=None, linestyles='solid',
11481149
self._request_autoscale_view()
11491150
return lines
11501151

1152+
@_api.make_keyword_only("3.9", "label")
11511153
@_preprocess_data(replace_names=["x", "ymin", "ymax", "colors"],
11521154
label_namer="x")
11531155
def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
@@ -1239,6 +1241,7 @@ def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
12391241
self._request_autoscale_view()
12401242
return lines
12411243

1244+
@_api.make_keyword_only("3.9", "orientation")
12421245
@_preprocess_data(replace_names=["positions", "lineoffsets",
12431246
"linelengths", "linewidths",
12441247
"colors", "linestyles"])
@@ -1742,6 +1745,7 @@ def plot(self, *args, scalex=True, scaley=True, data=None, **kwargs):
17421745
self._request_autoscale_view("y")
17431746
return lines
17441747

1748+
@_api.make_keyword_only("3.9", "tz")
17451749
@_preprocess_data(replace_names=["x", "y"], label_namer="y")
17461750
@_docstring.dedent_interpd
17471751
def plot_date(self, x, y, fmt='o', tz=None, xdate=True, ydate=False,
@@ -2045,6 +2049,7 @@ def acorr(self, x, **kwargs):
20452049
"""
20462050
return self.xcorr(x, x, **kwargs)
20472051

2052+
@_api.make_keyword_only("3.9", "normed")
20482053
@_preprocess_data(replace_names=["x", "y"], label_namer="y")
20492054
def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none,
20502055
usevlines=True, maxlags=10, **kwargs):
@@ -3112,6 +3117,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
31123117
self.add_container(stem_container)
31133118
return stem_container
31143119

3120+
@_api.make_keyword_only("3.9", "explode")
31153121
@_preprocess_data(replace_names=["x", "explode", "labels", "colors"])
31163122
def pie(self, x, explode=None, labels=None, colors=None,
31173123
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1,
@@ -3388,6 +3394,7 @@ def _errorevery_to_mask(x, errorevery):
33883394
everymask[errorevery] = True
33893395
return everymask
33903396

3397+
@_api.make_keyword_only("3.9", "ecolor")
33913398
@_preprocess_data(replace_names=["x", "y", "xerr", "yerr"],
33923399
label_namer="y")
33933400
@_docstring.dedent_interpd
@@ -3764,6 +3771,7 @@ def apply_mask(arrays, mask):
37643771

37653772
return errorbar_container # (l0, caplines, barcols)
37663773

3774+
@_api.make_keyword_only("3.9", "notch")
37673775
@_preprocess_data()
37683776
def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
37693777
positions=None, widths=None, patch_artist=None,
@@ -4078,6 +4086,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None,
40784086
capwidths=capwidths)
40794087
return artists
40804088

4089+
@_api.make_keyword_only("3.9", "widths")
40814090
def bxp(self, bxpstats, positions=None, widths=None, vert=True,
40824091
patch_artist=False, shownotches=False, showmeans=False,
40834092
showcaps=True, showbox=True, showfliers=True,
@@ -4531,6 +4540,7 @@ def invalid_shape_exception(csize, xsize):
45314540
colors = None # use cmap, norm after collection is created
45324541
return c, colors, edgecolors
45334542

4543+
@_api.make_keyword_only("3.9", "marker")
45344544
@_preprocess_data(replace_names=["x", "y", "s", "linewidths",
45354545
"edgecolors", "c", "facecolor",
45364546
"facecolors", "color"],
@@ -4811,6 +4821,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
48114821

48124822
return collection
48134823

4824+
@_api.make_keyword_only("3.9", "gridsize")
48144825
@_preprocess_data(replace_names=["x", "y", "C"], label_namer="y")
48154826
@_docstring.dedent_interpd
48164827
def hexbin(self, x, y, C=None, gridsize=100, bins=None,
@@ -6590,6 +6601,7 @@ def clabel(self, CS, levels=None, **kwargs):
65906601

65916602
#### Data analysis
65926603

6604+
@_api.make_keyword_only("3.9", "range")
65936605
@_preprocess_data(replace_names=["x", 'weights'], label_namer="x")
65946606
def hist(self, x, bins=None, range=None, density=False, weights=None,
65956607
cumulative=False, bottom=None, histtype='bar', align='mid',
@@ -7134,6 +7146,7 @@ def stairs(self, values, edges=None, *,
71347146
self._request_autoscale_view()
71357147
return patch
71367148

7149+
@_api.make_keyword_only("3.9", "range")
71377150
@_preprocess_data(replace_names=["x", "y", "weights"])
71387151
@_docstring.dedent_interpd
71397152
def hist2d(self, x, y, bins=10, range=None, density=False, weights=None,
@@ -7343,6 +7356,7 @@ def ecdf(self, x, weights=None, *, complementary=False,
73437356
line.sticky_edges.x[:] = [0, 1]
73447357
return line
73457358

7359+
@_api.make_keyword_only("3.9", "NFFT")
73467360
@_preprocess_data(replace_names=["x"])
73477361
@_docstring.dedent_interpd
73487362
def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
@@ -7454,6 +7468,7 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
74547468
else:
74557469
return pxx, freqs, line
74567470

7471+
@_api.make_keyword_only("3.9", "NFFT")
74577472
@_preprocess_data(replace_names=["x", "y"], label_namer="y")
74587473
@_docstring.dedent_interpd
74597474
def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
@@ -7556,6 +7571,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
75567571
else:
75577572
return pxy, freqs, line
75587573

7574+
@_api.make_keyword_only("3.9", "Fs")
75597575
@_preprocess_data(replace_names=["x"])
75607576
@_docstring.dedent_interpd
75617577
def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
@@ -7642,6 +7658,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None,
76427658

76437659
return spec, freqs, line
76447660

7661+
@_api.make_keyword_only("3.9", "Fs")
76457662
@_preprocess_data(replace_names=["x"])
76467663
@_docstring.dedent_interpd
76477664
def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
@@ -7711,6 +7728,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None,
77117728

77127729
return spec, freqs, lines[0]
77137730

7731+
@_api.make_keyword_only("3.9", "Fs")
77147732
@_preprocess_data(replace_names=["x"])
77157733
@_docstring.dedent_interpd
77167734
def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
@@ -7780,6 +7798,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None,
77807798

77817799
return spec, freqs, lines[0]
77827800

7801+
@_api.make_keyword_only("3.9", "NFFT")
77837802
@_preprocess_data(replace_names=["x", "y"])
77847803
@_docstring.dedent_interpd
77857804
def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
@@ -7844,6 +7863,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none,
78447863

78457864
return cxy, freqs
78467865

7866+
@_api.make_keyword_only("3.9", "NFFT")
78477867
@_preprocess_data(replace_names=["x"])
78487868
@_docstring.dedent_interpd
78497869
def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
@@ -8000,6 +8020,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
80008020

80018021
return spec, freqs, t, im
80028022

8023+
@_api.make_keyword_only("3.9", "precision")
80038024
@_docstring.dedent_interpd
80048025
def spy(self, Z, precision=0, marker=None, markersize=None,
80058026
aspect='equal', origin="upper", **kwargs):
@@ -8190,6 +8211,7 @@ def matshow(self, Z, **kwargs):
81908211
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True))
81918212
return im
81928213

8214+
@_api.make_keyword_only("3.9", "vert")
81938215
@_preprocess_data(replace_names=["dataset"])
81948216
def violinplot(self, dataset, positions=None, vert=True, widths=0.5,
81958217
showmeans=False, showextrema=True, showmedians=False,
@@ -8295,6 +8317,7 @@ def _kde_method(X, coords):
82958317
widths=widths, showmeans=showmeans,
82968318
showextrema=showextrema, showmedians=showmedians)
82978319

8320+
@_api.make_keyword_only("3.9", "vert")
82988321
def violin(self, vpstats, positions=None, vert=True, widths=0.5,
82998322
showmeans=False, showextrema=True, showmedians=False):
83008323
"""

0 commit comments

Comments
 (0)