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

Skip to content

Commit 2c1cd6b

Browse files
Christopher-Bradshawtimhoffm
authored andcommitted
Allow all valid hist.bins strings to be set in the rcparams (#12908)
1 parent 2bd79f3 commit 2c1cd6b

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6380,7 +6380,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
63806380
63816381
With Numpy 1.11 or newer, you can alternatively provide a string
63826382
describing a binning strategy, such as 'auto', 'sturges', 'fd',
6383-
'doane', 'scott', 'rice', 'sturges' or 'sqrt', see
6383+
'doane', 'scott', 'rice' or 'sqrt', see
63846384
`numpy.histogram`.
63856385
63866386
The default is taken from :rc:`hist.bins`.

lib/matplotlib/rcsetup.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,8 @@ def validate_cycler(s):
914914

915915

916916
def validate_hist_bins(s):
917-
if cbook._str_equal(s, "auto"):
917+
valid_strs = ["auto", "sturges", "fd", "doane", "scott", "rice", "sqrt"]
918+
if isinstance(s, str) and s in valid_strs:
918919
return s
919920
try:
920921
return int(s)
@@ -924,8 +925,8 @@ def validate_hist_bins(s):
924925
return validate_floatlist(s)
925926
except ValueError:
926927
pass
927-
raise ValueError("'hist.bins' must be 'auto', an int or " +
928-
"a sequence of floats")
928+
raise ValueError("'hist.bins' must be one of {}, an int or"
929+
" a sequence of floats".format(valid_strs))
929930

930931

931932
def validate_animation_writer_path(p):

lib/matplotlib/tests/test_rcparams.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ def generate_validator_testcases(valid):
321321
},
322322
{'validator': validate_hist_bins,
323323
'success': (('auto', 'auto'),
324+
('fd', 'fd'),
324325
('10', 10),
325326
('1, 2, 3', [1, 2, 3]),
326327
([1, 2, 3], [1, 2, 3]),

0 commit comments

Comments
 (0)