-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Deprecate positional use of most arguments of plotting functions #27786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Positional parameters in plotting functions | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Many plotting functions will restrict positional arguments to the first few parameters | ||
in the future. All further configuration parameters will have to be passed as keyword | ||
arguments. This is to enforce better code and and allow for future changes with reduced | ||
risk of breaking existing code. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1100,6 +1100,7 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs): | |
self._request_autoscale_view("x") | ||
return p | ||
|
||
@_api.make_keyword_only("3.9", "label") | ||
@_preprocess_data(replace_names=["y", "xmin", "xmax", "colors"], | ||
label_namer="y") | ||
def hlines(self, y, xmin, xmax, colors=None, linestyles='solid', | ||
|
@@ -1191,6 +1192,7 @@ def hlines(self, y, xmin, xmax, colors=None, linestyles='solid', | |
self._request_autoscale_view() | ||
return lines | ||
|
||
@_api.make_keyword_only("3.9", "label") | ||
@_preprocess_data(replace_names=["x", "ymin", "ymax", "colors"], | ||
label_namer="x") | ||
def vlines(self, x, ymin, ymax, colors=None, linestyles='solid', | ||
|
@@ -1282,6 +1284,7 @@ def vlines(self, x, ymin, ymax, colors=None, linestyles='solid', | |
self._request_autoscale_view() | ||
return lines | ||
|
||
@_api.make_keyword_only("3.9", "orientation") | ||
@_preprocess_data(replace_names=["positions", "lineoffsets", | ||
"linelengths", "linewidths", | ||
"colors", "linestyles"]) | ||
|
@@ -2088,6 +2091,7 @@ def acorr(self, x, **kwargs): | |
""" | ||
return self.xcorr(x, x, **kwargs) | ||
|
||
@_api.make_keyword_only("3.9", "normed") | ||
@_preprocess_data(replace_names=["x", "y"], label_namer="y") | ||
def xcorr(self, x, y, normed=True, detrend=mlab.detrend_none, | ||
usevlines=True, maxlags=10, **kwargs): | ||
|
@@ -3155,6 +3159,7 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, | |
self.add_container(stem_container) | ||
return stem_container | ||
|
||
@_api.make_keyword_only("3.9", "explode") | ||
@_preprocess_data(replace_names=["x", "explode", "labels", "colors"]) | ||
def pie(self, x, explode=None, labels=None, colors=None, | ||
autopct=None, pctdistance=0.6, shadow=False, labeldistance=1.1, | ||
|
@@ -3434,6 +3439,7 @@ def _errorevery_to_mask(x, errorevery): | |
everymask[errorevery] = True | ||
return everymask | ||
|
||
@_api.make_keyword_only("3.9", "ecolor") | ||
@_preprocess_data(replace_names=["x", "y", "xerr", "yerr"], | ||
label_namer="y") | ||
@_docstring.dedent_interpd | ||
|
@@ -3810,6 +3816,7 @@ def apply_mask(arrays, mask): | |
|
||
return errorbar_container # (l0, caplines, barcols) | ||
|
||
@_api.make_keyword_only("3.9", "notch") | ||
@_preprocess_data() | ||
@_api.rename_parameter("3.9", "labels", "tick_labels") | ||
def boxplot(self, x, notch=None, sym=None, vert=None, whis=None, | ||
|
@@ -4144,6 +4151,7 @@ def boxplot(self, x, notch=None, sym=None, vert=None, whis=None, | |
capwidths=capwidths, label=label) | ||
return artists | ||
|
||
@_api.make_keyword_only("3.9", "widths") | ||
def bxp(self, bxpstats, positions=None, widths=None, vert=True, | ||
patch_artist=False, shownotches=False, showmeans=False, | ||
showcaps=True, showbox=True, showfliers=True, | ||
|
@@ -4636,6 +4644,7 @@ def invalid_shape_exception(csize, xsize): | |
colors = None # use cmap, norm after collection is created | ||
return c, colors, edgecolors | ||
|
||
@_api.make_keyword_only("3.9", "marker") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can see an arguament for pushing this one deeper ax.scatter(x, y, s, c, 'o') scans reasonably well, but I suspect is rare. |
||
@_preprocess_data(replace_names=["x", "y", "s", "linewidths", | ||
"edgecolors", "c", "facecolor", | ||
"facecolors", "color"], | ||
|
@@ -4916,6 +4925,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None, | |
|
||
return collection | ||
|
||
@_api.make_keyword_only("3.9", "gridsize") | ||
@_preprocess_data(replace_names=["x", "y", "C"], label_namer="y") | ||
@_docstring.dedent_interpd | ||
def hexbin(self, x, y, C=None, gridsize=100, bins=None, | ||
|
@@ -6698,6 +6708,7 @@ def clabel(self, CS, levels=None, **kwargs): | |
|
||
#### Data analysis | ||
|
||
@_api.make_keyword_only("3.9", "range") | ||
@_preprocess_data(replace_names=["x", 'weights'], label_namer="x") | ||
def hist(self, x, bins=None, range=None, density=False, weights=None, | ||
cumulative=False, bottom=None, histtype='bar', align='mid', | ||
|
@@ -7245,6 +7256,7 @@ def stairs(self, values, edges=None, *, | |
self._request_autoscale_view() | ||
return patch | ||
|
||
@_api.make_keyword_only("3.9", "range") | ||
@_preprocess_data(replace_names=["x", "y", "weights"]) | ||
@_docstring.dedent_interpd | ||
def hist2d(self, x, y, bins=10, range=None, density=False, weights=None, | ||
|
@@ -7454,6 +7466,7 @@ def ecdf(self, x, weights=None, *, complementary=False, | |
line.sticky_edges.x[:] = [0, 1] | ||
return line | ||
|
||
@_api.make_keyword_only("3.9", "NFFT") | ||
@_preprocess_data(replace_names=["x"]) | ||
@_docstring.dedent_interpd | ||
def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, | ||
|
@@ -7565,6 +7578,7 @@ def psd(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, | |
else: | ||
return pxx, freqs, line | ||
|
||
@_api.make_keyword_only("3.9", "NFFT") | ||
@_preprocess_data(replace_names=["x", "y"], label_namer="y") | ||
@_docstring.dedent_interpd | ||
def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None, | ||
|
@@ -7667,6 +7681,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None, | |
else: | ||
return pxy, freqs, line | ||
|
||
@_api.make_keyword_only("3.9", "Fs") | ||
@_preprocess_data(replace_names=["x"]) | ||
@_docstring.dedent_interpd | ||
def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None, | ||
|
@@ -7753,6 +7768,7 @@ def magnitude_spectrum(self, x, Fs=None, Fc=None, window=None, | |
|
||
return spec, freqs, line | ||
|
||
@_api.make_keyword_only("3.9", "Fs") | ||
@_preprocess_data(replace_names=["x"]) | ||
@_docstring.dedent_interpd | ||
def angle_spectrum(self, x, Fs=None, Fc=None, window=None, | ||
|
@@ -7822,6 +7838,7 @@ def angle_spectrum(self, x, Fs=None, Fc=None, window=None, | |
|
||
return spec, freqs, lines[0] | ||
|
||
@_api.make_keyword_only("3.9", "Fs") | ||
@_preprocess_data(replace_names=["x"]) | ||
@_docstring.dedent_interpd | ||
def phase_spectrum(self, x, Fs=None, Fc=None, window=None, | ||
|
@@ -7891,6 +7908,7 @@ def phase_spectrum(self, x, Fs=None, Fc=None, window=None, | |
|
||
return spec, freqs, lines[0] | ||
|
||
@_api.make_keyword_only("3.9", "NFFT") | ||
@_preprocess_data(replace_names=["x", "y"]) | ||
@_docstring.dedent_interpd | ||
def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, | ||
|
@@ -7955,6 +7973,7 @@ def cohere(self, x, y, NFFT=256, Fs=2, Fc=0, detrend=mlab.detrend_none, | |
|
||
return cxy, freqs | ||
|
||
@_api.make_keyword_only("3.9", "NFFT") | ||
@_preprocess_data(replace_names=["x"]) | ||
@_docstring.dedent_interpd | ||
def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, | ||
|
@@ -8111,6 +8130,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None, | |
|
||
return spec, freqs, t, im | ||
|
||
@_api.make_keyword_only("3.9", "precision") | ||
@_docstring.dedent_interpd | ||
def spy(self, Z, precision=0, marker=None, markersize=None, | ||
aspect='equal', origin="upper", **kwargs): | ||
|
@@ -8301,6 +8321,7 @@ def matshow(self, Z, **kwargs): | |
mticker.MaxNLocator(nbins=9, steps=[1, 2, 5, 10], integer=True)) | ||
return im | ||
|
||
@_api.make_keyword_only("3.9", "vert") | ||
@_preprocess_data(replace_names=["dataset"]) | ||
def violinplot(self, dataset, positions=None, vert=True, widths=0.5, | ||
showmeans=False, showextrema=True, showmedians=False, | ||
|
@@ -8412,6 +8433,7 @@ def _kde_method(X, coords): | |
widths=widths, showmeans=showmeans, | ||
showextrema=showextrema, showmedians=showmedians, side=side) | ||
|
||
@_api.make_keyword_only("3.9", "vert") | ||
def violin(self, vpstats, positions=None, vert=True, widths=0.5, | ||
showmeans=False, showextrema=True, showmedians=False, side='both'): | ||
""" | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to have some measure of consistency on which parameters are positional only (like for example the data parameters?)
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The central question is: Is code using the positional parameters understandable without knowing the signature? Mostly this results in positional data parameters. But with some exceptions:
fmt
is allowed positionally - inspired byplot
bins
in histograms because fromhist(data, 20)
it's conceivable that the inter is bins(debatable, but err on the permissive side)hlines
I've gone to the extreme and still allowed color and linestyles because if somebody has writtenhlines(y, xmin, xmax, 'red', 'dashed')
that's quite clear and I don't want to break their code.