Skip to content

Add hist.histtype rcParam. #12493

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

Closed
wants to merge 2 commits into from
Closed
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
7 changes: 7 additions & 0 deletions doc/users/next_whats_new/2018-10-11-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Introduction of :rc:`hist.histtype`
```````````````````````````````````

The default value of the ``histtype`` argument to `Axes.hist()` can now be
controlled using :rc:`hist.histtype`. For large numbers of bins, setting
this value to 'step' or 'stepfilled' can result in significant performance
improvements over 'bar', the current default.
54 changes: 26 additions & 28 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6259,7 +6259,7 @@ def table(self, **kwargs):

@_preprocess_data(replace_names=["x", 'weights'], label_namer="x")
def hist(self, x, bins=None, range=None, density=None, weights=None,
cumulative=False, bottom=None, histtype='bar', align='mid',
cumulative=False, bottom=None, histtype=None, align='mid',
orientation='vertical', rwidth=None, log=False,
color=None, label=None, stacked=False, normed=None,
**kwargs):
Expand Down Expand Up @@ -6319,7 +6319,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
is based on the specified bin range instead of the
range of x.

Default is ``None``
Default is ``None``.

density : bool, optional
If ``True``, the first element of the return tuple will
Expand All @@ -6343,7 +6343,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
the weights are normalized, so that the integral of the density
over the range remains 1.

Default is ``None``
Default is ``None``.

cumulative : bool, optional
If ``True``, then a histogram is computed where each bin gives the
Expand All @@ -6355,43 +6355,39 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
In this case, if *normed* and/or *density* is also ``True``, then
the histogram is normalized such that the first bin equals 1.

Default is ``False``
Default is ``False``.

bottom : array_like, scalar, or None
Location of the bottom baseline of each bin. If a scalar,
the base line for each bin is shifted by the same amount.
If an array, each bin is shifted independently and the length
of bottom must match the number of bins. If None, defaults to 0.

Default is ``None``
Default is ``None``.

histtype : {'bar', 'barstacked', 'step', 'stepfilled'}, optional
The type of histogram to draw.

- 'bar' is a traditional bar-type histogram. If multiple data
are given the bars are arranged side by side.
- 'bar' is a traditional bar-type histogram. If multiple data are
given the bars are arranged side by side.
- 'barstacked' is a bar-type histogram where multiple data are
stacked on top of each other.
- 'step' generates a lineplot that is by default unfilled.
- 'stepfilled' generates a lineplot that is by default filled.

- 'barstacked' is a bar-type histogram where multiple
data are stacked on top of each other.
For large numbers of bins, 'step' and 'stepfilled' can be
significantly faster than 'bar' and 'barstacked'.

- 'step' generates a lineplot that is by default
unfilled.

- 'stepfilled' generates a lineplot that is by default
filled.

Default is 'bar'
Default is taken from :rc:`hist.histtype`.

align : {'left', 'mid', 'right'}, optional
Controls how the histogram is plotted.

- 'left': bars are centered on the left bin edges.

- 'mid': bars are centered between the bin edges.

- 'right': bars are centered on the right bin edges.
- 'left': bars are centered on the left bin edges.
- 'mid': bars are centered between the bin edges.
- 'right': bars are centered on the right bin edges.

Default is 'mid'
Default is 'mid'.

orientation : {'horizontal', 'vertical'}, optional
If 'horizontal', `~matplotlib.pyplot.barh` will be used for
Expand All @@ -6403,35 +6399,35 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,

Ignored if *histtype* is 'step' or 'stepfilled'.

Default is ``None``
Default is ``None``.

log : bool, optional
If ``True``, the histogram axis will be set to a log scale. If
*log* is ``True`` and *x* is a 1D array, empty bins will be
filtered out and only the non-empty ``(n, bins, patches)``
will be returned.

Default is ``False``
Default is ``False``.

color : color or array_like of colors or None, optional
Color spec or sequence of color specs, one per dataset. Default
(``None``) uses the standard line color sequence.

Default is ``None``
Default is ``None``.

label : str or None, optional
String, or sequence of strings to match multiple datasets. Bar
charts yield multiple patches per dataset, but only the first gets
the label, so that the legend command will work as expected.

default is ``None``
Default is ``None``.

stacked : bool, optional
If ``True``, multiple data are stacked on top of each other If
If ``True``, multiple data are stacked on top of each other. If
``False`` multiple data are arranged side by side if histtype is
'bar' or on top of each other if histtype is 'step'

Default is ``False``
Default is ``False``.

normed : bool, optional
Deprecated; use the density keyword argument instead.
Expand Down Expand Up @@ -6478,6 +6474,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,

if bins is None:
bins = rcParams['hist.bins']
if histtype is None:
histtype = rcParams['hist.histtype']

# Validate string inputs here so we don't have to clutter
# subsequent code.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2625,7 +2625,7 @@ def hexbin(
@docstring.copy_dedent(Axes.hist)
def hist(
x, bins=None, range=None, density=None, weights=None,
cumulative=False, bottom=None, histtype='bar', align='mid',
cumulative=False, bottom=None, histtype=None, align='mid',
orientation='vertical', rwidth=None, log=False, color=None,
label=None, stacked=False, normed=None, *, data=None,
**kwargs):
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/rcsetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,10 @@ def _validate_linestyle(ls):

## Histogram properties
'hist.bins': [10, validate_hist_bins],
'hist.histtype': [
'bar',
ValidateInStrings(
'histtype', ['bar', 'barstacked', 'step', 'stepfilled'])],

## Boxplot properties
'boxplot.notch': [False, validate_bool],
Expand Down
1 change: 1 addition & 0 deletions matplotlibrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@
#hist.bins : 10 ## The default number of histogram bins.
## If Numpy 1.11 or later is
## installed, may also be `auto`
#hist.histtype : bar ## The default histtype.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be useful to list the options here

## The default histtype. One of 'bar', 'barstacked', 'step', 'stepfilled'.


#### SCATTER PLOTS
#scatter.marker : o ## The default marker type for scatter plots.
Expand Down