From 77099222af59573d9b4794348ff4ad2f2e19e63d Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Tue, 17 Nov 2015 22:21:53 -0500 Subject: [PATCH 1/3] DOC: add missing whatsnew + classic style to #5503 --- doc/users/whats_new/ticks_rcparams.rst | 6 +++++- lib/matplotlib/mpl-data/stylelib/classic.mplstyle | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/users/whats_new/ticks_rcparams.rst b/doc/users/whats_new/ticks_rcparams.rst index 63fef6b92868..468bbbf10535 100644 --- a/doc/users/whats_new/ticks_rcparams.rst +++ b/doc/users/whats_new/ticks_rcparams.rst @@ -3,4 +3,8 @@ New rcParams The parameters `xtick.top`, `xtick.bottom`, `ytick.left` and `ytick.right` were added to control where the ticks -are drawn. \ No newline at end of file +are drawn. + +``hist.bins`` to control the default number of bins to use in +`~matplotlib.axes.Axes.hist`. This can be an ``int``, an array, or +``'auto'`` if numpy > 1.11 is installed. diff --git a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle index 0f61a53ac8cd..af8c392811ac 100644 --- a/lib/matplotlib/mpl-data/stylelib/classic.mplstyle +++ b/lib/matplotlib/mpl-data/stylelib/classic.mplstyle @@ -29,6 +29,8 @@ patch.facecolor : b patch.edgecolor : k patch.antialiased : True # render patches in antialiased (no jaggies) +hist.bins : 10 + ### FONT # # font properties used by text.Text. See From 5e0ca92178f6a006bd8ca0787bcd43a6dac01b33 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 23 Nov 2015 22:13:01 -0500 Subject: [PATCH 2/3] FIX: add custom validator for hist.bins --- lib/matplotlib/rcsetup.py | 19 ++++++++++++++++++- lib/matplotlib/tests/test_rcparams.py | 15 +++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index 97d0015a4ec6..f52e8305f335 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -770,6 +770,23 @@ def validate_cycler(s): return cycler_inst +def validate_hist_bins(s): + if isinstance(s, six.text_type) and s == 'auto': + return s + try: + return int(s) + except (TypeError, ValueError): + pass + + try: + return validate_floatlist(s) + except ValueError: + pass + + raise ValueError("'hist.bins' must be 'auto', an int or " + + "a sequence of floats") + + # a map from key -> value, converter defaultParams = { 'backend': ['Agg', validate_backend], # agg is certainly @@ -814,7 +831,7 @@ def validate_cycler(s): 'patch.antialiased': [True, validate_bool], # antialiased (no jaggies) ## Histogram properties - 'hist.bins': [10, validate_any], + 'hist.bins': [10, validate_hist_bins], ## Boxplot properties 'boxplot.notch': [False, validate_bool], diff --git a/lib/matplotlib/tests/test_rcparams.py b/lib/matplotlib/tests/test_rcparams.py index 66def5609e36..bc39a50ed22f 100644 --- a/lib/matplotlib/tests/test_rcparams.py +++ b/lib/matplotlib/tests/test_rcparams.py @@ -27,7 +27,8 @@ validate_nseq_int, validate_nseq_float, validate_cycler, - validate_hatch) + validate_hatch, + validate_hist_bins) mpl.rc('text', usetex=False) @@ -363,7 +364,17 @@ def test_validators(): ), 'fail': (('fish', ValueError), ), - } + }, + {'validator': validate_hist_bins, + 'success': (('auto', 'auto'), + ('10', 10), + ('1, 2, 3', [1, 2, 3]), + ([1, 2, 3], [1, 2, 3]), + (np.arange(15), np.arange(15)) + ), + 'fail': (('aardvark', ValueError), + ) + } ) for validator_dict in validation_tests: From 7d8d78e8ca99ae475936bf01c22cbf02a90e1902 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Mon, 23 Nov 2015 22:30:49 -0500 Subject: [PATCH 3/3] DOC: fixed docs --- doc/users/whats_new/ticks_rcparams.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/users/whats_new/ticks_rcparams.rst b/doc/users/whats_new/ticks_rcparams.rst index 468bbbf10535..6f7f0c60bf55 100644 --- a/doc/users/whats_new/ticks_rcparams.rst +++ b/doc/users/whats_new/ticks_rcparams.rst @@ -1,10 +1,10 @@ New rcParams ------------ -The parameters `xtick.top`, `xtick.bottom`, `ytick.left` -and `ytick.right` were added to control where the ticks +The parameters ``xtick.top``, ``xtick.bottom``, ``ytick.left`` +and ``ytick.right`` were added to control where the ticks are drawn. ``hist.bins`` to control the default number of bins to use in -`~matplotlib.axes.Axes.hist`. This can be an ``int``, an array, or -``'auto'`` if numpy > 1.11 is installed. +`~matplotlib.axes.Axes.hist`. This can be an `int`, a list of floats, or +``'auto'`` if numpy >= 1.11 is installed.