In [ ]:
import numpy as np
import holoviews as hv
hv.extension('bokeh')
The Bars
Element uses bars to show discrete, numerical comparisons across categories. One axis of the chart shows the specific categories being compared and the other axis represents a continuous value.
Bars may also be grouped or stacked by supplying a second key dimension representing sub-categories. Therefore the Bars
Element expects a tabular data format with one or two key dimensions (kdims
) and one or more value dimensions (vdims
). See the Tabular Datasets user guide for supported data formats, which include arrays, pandas dataframes and dictionaries of arrays.
In [ ]:
data = [('one',8),('two', 10), ('three', 16), ('four', 8), ('five', 4), ('six', 1)]
bars = hv.Bars(data, hv.Dimension('Car occupants'), 'Count')
bars
You can 'slice' a Bars
element by selecting categories as follows:
In [ ]:
bars[['one', 'two', 'three']] + bars[['four', 'five', 'six']]
Bars
support nested categorical grouping as well as stacking if more than one key dimension is defined, to switch between the two set stacked=True/False
:
In [ ]:
from itertools import product
np.random.seed(3)
index, groups = ['A', 'B'], ['a', 'b']
keys = product(index, groups)
bars = hv.Bars([k+(np.random.rand()*100.,) for k in keys],
['Index', 'Group'], 'Count')
stacked = bars.opts(stacked=True, clone=True)
bars.relabel(group='Grouped') + stacked.relabel(group='Stacked')
For full documentation and the available style and plot options, use hv.help(hv.Bars).