Lollipop plot

A lollipop chart is an alernative to the more usual barplot. Python allows to build lollipops thanks to the matplotlib library, as shown in the examples below. The strategy here is to use the stem() function or to hack the vline() function depending on your input format.

⏱ Quick start

# Create a dataframe
import pandas as pd
df = pd.DataFrame({'group':list(map(chr, range(65, 85))), 'values':np.random.uniform(size=20) })

# Reorder it following the values:
ordered_df = df.sort_values(by='values')

# Make the plot
plt.xticks( my_range, ordered_df['group'])

Matplotlib logoLollipop plot with Matplotlib

Matplotlib is probably the most famous and flexible python library for data visualization. It is appropriate to build any kind of chart, including the lollipop plot thanks to its stem() function.

Matplotlib logoBest python lollipop plot examples

The web is full of astonishing charts made by awesome bloggers, (often using R). The Python graph gallery tries to display (or translate from R) some of the best creations and explain how their source code works. If you want to display your work here, please drop me a word or even better, submit a Pull Request!


👋 This document is a work by Yan Holtz. You can contribute on github, send me a feedback on twitter or subscribe to the newsletter to know when new examples are published! 🔥