bff.plot.plot_counter¶
-
bff.plot.
plot_counter
(counter, label_x='x', label_y='y', title='Bar chart', width=0.9, threshold=0, vertical=True, ax=None, rotation_xticks=None, grid='y', figsize=14, 5, dpi=80, style='default', **kwargs)¶ Plot the values of a counter as a bar plot.
Values above the ratio are written as text on top of the bar.
- Parameters
counter (collections.Counter or dictionary) – Counter or dictionary to plot.
label_x (str, default 'x') – Label for x axis.
label_y (str, default 'y') – Label for y axis.
title (str, default 'Bar chart') – Title for the plot (axis level).
width (float, default 0.9) – Width of the bar. If below 1.0, there will be space between them.
threshold (int, default = 0) – Threshold above which the value is written on the plot as text. By default, all bar have their text.
vertical (bool, default True) – By default, vertical bar. If set to False, will plot using plt.barh and inverse the labels.
ax (plt.axes, optional) – Axes from matplotlib, if None, new figure and axes will be created.
loc (str or int, default 'best') – Location of the legend on the plot. Either the legend string or legend code are possible.
rotation_xticks (float, optional) – Rotation of x ticks if any. Set to 90 to put them vertically.
grid (str or None, default 'y') – Axis where to activate the grid (‘both’, ‘x’, ‘y’). To turn off, set to None.
figsize (Tuple[int, int], default (14, 5)) – Size of the figure to plot.
dpi (int, default 80) – Resolution of the figure.
style (str, default 'default') – Style to use for matplotlib.pyplot. The style is use only in this context and not applied globally.
**kwargs – Additional keyword arguments to be passed to the plt.plot function from matplotlib.
- Returns
Axes returned by the plt.subplots function.
- Return type
plt.axes
Examples
>>> from collections import Counter >>> counter = Counter({'red': 4, 'blue': 2}) >>> plot_counter(counter, title='MyTitle', rotation_xticks=90)