Horizontal Bar Chart#

A horizontal bar chart for comparing category values along the y-axis. This example uses the penguins dataset to show average body mass per species.

import hvplot.pandas  # noqa

df = hvplot.sampledata.penguins('pandas')
grouped = df.groupby('species', observed=True)['body_mass_g'].mean()

grouped.hvplot.barh(
    x='species',
    y='body_mass_g',
    title='Horizontal Bar Chart (Bokeh)',
    ylabel='Body Mass (g)',
    xlabel='Species',
)
import hvplot.pandas  # noqa
hvplot.extension('matplotlib')

df = hvplot.sampledata.penguins('pandas')
grouped = df.groupby('species', observed=True)['body_mass_g'].mean()

grouped.hvplot.barh(
    x='species',
    y='body_mass_g',
    title='Horizontal Bar Chart (Matplotlib)',
    ylabel='Body Mass (g)',
    xlabel='Species',
)
grouped
species
Adelie       3700.662252
Chinstrap    3733.088235
Gentoo       5076.016260
Name: body_mass_g, dtype: float64
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.