Fundamentals 8 min read

Create Stunning Lollipop Charts in Excel and Python: Step‑by‑Step Guide

Learn how to build eye‑catching lollipop (棒棒糖) charts using both Excel and Python’s matplotlib, covering data preparation, combining bar and scatter plots, styling axes, employing the stem function, and handling large datasets, with full code snippets and visual examples.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Create Stunning Lollipop Charts in Excel and Python: Step‑by‑Step Guide

Excel Lollipop Chart

Data preparation: duplicate the original data column to obtain two identical columns. Select the data and insert a combo chart, combining a column chart and a scatter plot, which yields a basic lollipop chart.

Adjust styles as needed, especially the x‑axis position, which is relatively complex. Right‑click the y‑axis, choose "Format Axis", then set the horizontal axis position and label. Set the x‑axis value (e.g., 0.8) and place the label at the bottom of the chart.

You can also customize the bar and scatter styles, such as colors and shapes, by selecting individual elements.

Python Lollipop Chart

Bar + Scatter Method

Combine plt.bar and plt.scatter to create a lollipop chart. Different styles can be set for each component.

n = len(values)
colors1 = ["red"] + ((n-1)*["olive"])
colors2 = ["red"] + ((n-1)*["blue"])
plt.rcParams['figure.figsize'] = (23.5, 10)
plt.bar(values.index, values.values,
        color=colors1, width=0.05)  # set bar color and width
plt.scatter(values.index, values.values,
            color=colors2, s=50)   # set marker size
plt.show()

Styling

Move the x‑axis upward by adding a constant offset v (negative) to all y values and setting the lower limit of the y‑axis.

Shift all y values: y = y + v Set y‑axis lower limit: plt.ylim(v, 0.6) Draw a baseline using either plt.plot or plt.axhline:

plt.style.use('ggplot')
plt.rcParams['figure.figsize'] = (23.5, 10)
plt.rcParams['axes.unicode_minus'] = False
v = -0.8
plt.bar(values.index, values.values+v, color=colors1, width=0.05)
plt.scatter(values.index, values.values+v, color=colors2, s=60)
plt.axhline(y=0, xmin=0.045, xmax=0.955, color='darkblue', linestyle='--')
plt.ylim(v, 0.6)
plt.show()

Stem Function Method

Matplotlib’s stem function can draw a lollipop chart in a single line. Main parameters are stem(x, y, linefmt=None, markerfmt=None, basefmt=None).

stem(x, y, linefmt=None, markerfmt=None, basefmt=None) x : array‑like Data for the x‑axis y : array‑like Data for the y‑axis linefmt : str, optional Color and line style for vertical lines, e.g., 'r-' markerfmt : str, optional Marker type and color, default 'C0o' basefmt : str, default: 'C3-' Format for the baseline (y=0)

Customize colors with plt.setp and adjust the baseline using the bottom argument.

n = len(values2)
colors1 = ["red"] + ((n-1)*["olive"])
(markers, stemlines, baseline) = plt.stem(values2, markerfmt="C0o")
plt.setp(stemlines, linestyle="-", color=colors1, linewidth=0.5)
plt.setp(baseline, linestyle="--", color="darkblue", linewidth=2)
plt.show()

Set the baseline position with bottom=0.8 and apply a dark background style for better contrast.

plt.style.use('dark_background')
plt.grid(0)
(markers, stemlines, baseline) = plt.stem(values2, bottom=0.8, markerfmt="C3o")
plt.setp(stemlines, linestyle="-", color="y", linewidth=2)
plt.show()

When the dataset is large, the lollipop chart still displays clearly, as demonstrated by the following examples.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Data visualizationExcelMatplotlibLollipop Chart
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.