Skip to content

Allow all valid hist.bins strings to be set in the rcparams #12908

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 1 commit into from
Dec 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6380,7 +6380,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,

With Numpy 1.11 or newer, you can alternatively provide a string
describing a binning strategy, such as 'auto', 'sturges', 'fd',
'doane', 'scott', 'rice', 'sturges' or 'sqrt', see
'doane', 'scott', 'rice' or 'sqrt', see
`numpy.histogram`.

The default is taken from :rc:`hist.bins`.
Expand Down
7 changes: 4 additions & 3 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,8 @@ def validate_cycler(s):


def validate_hist_bins(s):
if cbook._str_equal(s, "auto"):
valid_strs = ["auto", "sturges", "fd", "doane", "scott", "rice", "sqrt"]
if isinstance(s, str) and s in valid_strs:
return s
try:
return int(s)
Expand All @@ -924,8 +925,8 @@ def validate_hist_bins(s):
return validate_floatlist(s)
except ValueError:
pass
raise ValueError("'hist.bins' must be 'auto', an int or " +
"a sequence of floats")
raise ValueError("'hist.bins' must be one of {}, an int or"
" a sequence of floats".format(valid_strs))


def validate_animation_writer_path(p):
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ def generate_validator_testcases(valid):
},
{'validator': validate_hist_bins,
'success': (('auto', 'auto'),
('fd', 'fd'),
('10', 10),
('1, 2, 3', [1, 2, 3]),
([1, 2, 3], [1, 2, 3]),
Expand Down