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

Skip to content

Commit 080d9d3

Browse files
committed
Add hist.histtype rcParam.
histtype='stepfilled' is significantly faster than the current default ('bar') for large numbers of bins, but changing the default would cause backcompat problems. The 'hist.histtype' rcParam is introduced with the explicit intent of preparing this transition (later making 'stepfilled' (or perhaps 'step') the default and then deprecating the rcParam, to avoid neverending growth of the rcParam list).
1 parent 4b276d3 commit 080d9d3

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6259,7 +6259,7 @@ def table(self, **kwargs):
62596259

62606260
@_preprocess_data(replace_names=["x", 'weights'], label_namer="x")
62616261
def hist(self, x, bins=None, range=None, density=None, weights=None,
6262-
cumulative=False, bottom=None, histtype='bar', align='mid',
6262+
cumulative=False, bottom=None, histtype=None, align='mid',
62636263
orientation='vertical', rwidth=None, log=False,
62646264
color=None, label=None, stacked=False, normed=None,
62656265
**kwargs):
@@ -6375,7 +6375,10 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
63756375
- 'step' generates a lineplot that is by default unfilled.
63766376
- 'stepfilled' generates a lineplot that is by default filled.
63776377
6378-
Default is 'bar'.
6378+
For large numbers of bins, 'step' and 'stepfilled' can be
6379+
significantly faster than 'bar' and 'barstacked'.
6380+
6381+
Default is taken from :rc:`hist.histtype`.
63796382
63806383
align : {'left', 'mid', 'right'}, optional
63816384
Controls how the histogram is plotted.
@@ -6471,6 +6474,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64716474

64726475
if bins is None:
64736476
bins = rcParams['hist.bins']
6477+
if histtype is None:
6478+
histtype = rcParams['hist.histtype']
64746479

64756480
# Validate string inputs here so we don't have to clutter
64766481
# subsequent code.

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2625,7 +2625,7 @@ def hexbin(
26252625
@docstring.copy_dedent(Axes.hist)
26262626
def hist(
26272627
x, bins=None, range=None, density=None, weights=None,
2628-
cumulative=False, bottom=None, histtype='bar', align='mid',
2628+
cumulative=False, bottom=None, histtype=None, align='mid',
26292629
orientation='vertical', rwidth=None, log=False, color=None,
26302630
label=None, stacked=False, normed=None, *, data=None,
26312631
**kwargs):

lib/matplotlib/rcsetup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ def _validate_linestyle(ls):
10341034

10351035
## Histogram properties
10361036
'hist.bins': [10, validate_hist_bins],
1037+
'hist.histtype': [
1038+
'bar',
1039+
ValidateInStrings(
1040+
'histtype', ['bar', 'barstacked', 'step', 'stepfilled'])],
10371041

10381042
## Boxplot properties
10391043
'boxplot.notch': [False, validate_bool],

matplotlibrc.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@
481481
#hist.bins : 10 ## The default number of histogram bins.
482482
## If Numpy 1.11 or later is
483483
## installed, may also be `auto`
484+
#hist.histtype : bar ## The default histtype.
484485

485486
#### SCATTER PLOTS
486487
#scatter.marker : o ## The default marker type for scatter plots.

0 commit comments

Comments
 (0)