From f1b89b209e9898e7f87ba3cb4f41b62aab6c82ed Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Tue, 17 Nov 2015 17:51:34 -0500 Subject: [PATCH] Fix #4487: Take hist bins from rcParam --- lib/matplotlib/axes/_axes.py | 11 ++++++++--- lib/matplotlib/rcsetup.py | 3 +++ matplotlibrc.template | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index abacbc4c715a..3ad6811e4190 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5684,7 +5684,7 @@ def table(self, **kwargs): @unpack_labeled_data(replace_names=["x", 'weights'], label_namer="x") @docstring.dedent_interpd - def hist(self, x, bins=10, range=None, normed=False, weights=None, + def hist(self, x, bins=None, range=None, normed=False, weights=None, cumulative=False, bottom=None, histtype='bar', align='mid', orientation='vertical', rwidth=None, log=False, color=None, label=None, stacked=False, @@ -5710,14 +5710,16 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, Input values, this takes either a single array or a sequency of arrays which are not required to be of the same length - bins : integer or array_like, optional + bins : integer or array_like or 'auto', optional If an integer is given, `bins + 1` bin edges are returned, consistently with :func:`numpy.histogram` for numpy version >= 1.3. Unequally spaced bins are supported if `bins` is a sequence. - default is 10 + If Numpy 1.11 is installed, may also be ``'auto'``. + + Default is taken from the rcParam ``hist.bins``. range : tuple or None, optional The lower and upper range of the bins. Lower and upper outliers @@ -5879,6 +5881,9 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None, if np.isscalar(x): x = [x] + if bins is None: + bins = rcParams['hist.bins'] + # xrange becomes range after 2to3 bin_range = range range = __builtins__["range"] diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index d3705005c14e..97d0015a4ec6 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -813,6 +813,9 @@ def validate_cycler(s): 'patch.facecolor': ['b', validate_color], # blue 'patch.antialiased': [True, validate_bool], # antialiased (no jaggies) + ## Histogram properties + 'hist.bins': [10, validate_any], + ## Boxplot properties 'boxplot.notch': [False, validate_bool], 'boxplot.vertical': [True, validate_bool], diff --git a/matplotlibrc.template b/matplotlibrc.template index 705e894442dd..0aa172251f82 100644 --- a/matplotlibrc.template +++ b/matplotlibrc.template @@ -376,6 +376,11 @@ backend : %(backend)s ### ERRORBAR PLOTS #errorbar.capsize : 3 # length of end cap on error bars in pixels +### HISTOGRAM PLOTS +#hist.bins : 10 # The default number of histogram bins. + # If Numpy 1.11 or later is + # installed, may also be `auto` + ### Agg rendering ### Warning: experimental, 2008/10/10 #agg.path.chunksize : 0 # 0 to disable; values in the range