Discrete histogram
- plot_utils.discrete_histogram(x, fig=None, ax=None, figsize=(5, 3), dpi=100, color=None, alpha=None, rot=0, logy=False, title=None, xlabel=None, ylabel='Number of occurrences', show_xticklabel=True)[source]
Plot a discrete histogram based on the given data
x
, such as below:N ^ | | ____ | | | ____ | | | | | | ____ | | | | | | | | | | | | | | | | | | ____ | | | | | | | | | | | | | | | | | | -|---------------------------------------> x x1 x2 x3 x4 ...
In the figure, N is the number of occurences for x1, x2, x3, x4, etc. And x1, x2, x3, x4, etc. are the discrete values within
x
.- Parameters:
x (list, numpy.ndarray, pandas.Series, or dict) – Data to be visualized. If
x
is a list, numpy arrary, or pandas Series, the content ofx
is analyzed and counts ofx
’s values are plotted. Ifx
is a dict, thenx
’s keys are treated as discrete values andx
’s values are treated as counts.fig (matplotlib.figure.Figure or
None
) – Figure object. If None, a new figure will be created.ax (matplotlib.axes._subplots.AxesSubplot or
None
) – Axes object. If None, a new axes will be created.figsize ((float, float)) – Figure size in inches, as a tuple of two numbers. The figure size of
fig
(if notNone
) will override this parameter.dpi (float) – Figure resolution. The dpi of
fig
(if notNone
) will override this parameter.color (str, list<float>, or
None
) – Color of bar. IfNone
, the default color (muted blue) is used.alpha (float or
None
) – Opacity of bar. IfNone
, the default value (1.0) is used.rot (float or int) – Rotation angle (degrees) of X axis label. Default = 0 (upright label).
logy (bool) – Whether or not to use log scale for the Y axis.
title (str) – The title of the plot.
xlabel (str) – The X axis label.
ylabel (str) – The Y axis label.
show_xticklabel (bool) – Whether or not to show the X tick labels (the names of the classes).
- Returns:
fig (matplotlib.figure.Figure) – The figure object being created or being passed into this function.
ax (matplotlib.axes._subplots.AxesSubplot) – The axes object being created or being passed into this function.
value_count (pandas.Series) – The counts of each discrete values within
x
(ifx
is an array) with each values sorted in ascending order, or the pandas Series generated fromx
(ifx
is a dict).
Notes
References:
http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.plot.html http://pandas.pydata.org/pandas-docs/version/0.18.1/visualization.html#bar-plots
See also
plot_ranking
Plot bars showing the ranking of the data