Lollipop Plot#

Lollipop plots can replace traditional bar plots, for example to reduce clutter when bars would look too “heavy” or overwhelming. hvPlot does not provide a built-in function to build such plot, instead, this example overlays a hvplot.scatter plot with (for the dot at the end) with vertical lines created with the holoviews.Segments element.

Note

This type of plot can also be called stem plot, which is how Matplotlib calls it. Stem plot is a somewhat ambiguous name that can be confused with stem-and-leaf plots.

import pandas as pd
import holoviews as hv
import hvplot.pandas  # noqa

df = pd.DataFrame({'type': list('ABCDEF'), 'value': [10, 50, 30, 35, 60, 20]})

# Create line segments for each stem
segments = hv.Segments(
    [(xv, 0, xv, yv) for xv, yv in zip(df['type'], df['value'])]
).opts(line_width=4, color='lightgrey')
# Markers at the top
markers = df.hvplot.scatter(x='type', y='value', size=200)

(segments * markers).opts(
    height=300,
    width=600,
    ylim=(0, None),
    xlabel='Type',
    ylabel='Value',
    title='Lollipop Plot'
)
import pandas as pd
import holoviews as hv
import hvplot.pandas  # noqa

hv.extension('matplotlib')

df = pd.DataFrame({'type': list(range(6)), 'value': [10, 50, 30, 35, 60, 20]})

# Create line segments for each stem
segments = hv.Segments(
    [(xv, 0, xv, yv) for xv, yv in zip(df['type'], df['value'])]
).opts(linewidth=4, color='lightgrey')
# Markers at the top
markers = df.hvplot.scatter(x='type', y='value').opts(s=250)

(segments * markers).opts(
    ylim=(0, None),
    xlabel='Type',
    ylabel='Value',
    title='Lollipop Plot'
)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.