Custom lollipop plot


While the previous post explains how to draw a lollipop plot using matplotlib, this post aims to describe the customization you can apply to 3 main parts: the stem, the markers and the baseline. Note that for all of these 3 components, we first build the plot with the stem() function, and then customize it with the setp() function.

Markers

You can easily remove the dots of the stem plot with the parameter markerfmt. It is also possible to change color, shape and size of the markers using setp() function.

# libraries
import matplotlib.pyplot as plt
import numpy as np
 
# create data
values=np.random.uniform(size=40)
 
# plot without markers
plt.stem(values, markerfmt=' ')
plt.show()
 
# change color and shape and size and edges
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(markers, marker='D', markersize=10, markeredgecolor="orange", markeredgewidth=2)
plt.show()

Baseline

The position of the baseline can be changed using bottom argument in the stem() functon. You can also customize the baseline: remove it, change its size, color, and so on using the setp() function.

# libraries
import matplotlib.pyplot as plt
import numpy as np

# create data
values=np.random.uniform(size=100)
 
# position is customized with the `bottom` argument
plt.stem(values, markerfmt=' ', bottom=0.5)
plt.show()
 
# hide the baseline
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(baseline, visible=False)
plt.show()
 
# hide the baseline - second way
plt.stem(values, basefmt=" ")
plt.show()
 
# custom the color and line style of the baseline 
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(baseline, linestyle="-", color="grey", linewidth=6)
plt.show()

Stem

The stems can be customized as well. All the feature that you can apply to a line plot can be applied to the stem: color, width, type, transparency etc.

# libraries
import matplotlib.pyplot as plt
import numpy as np

# create data
values=np.random.uniform(size=100)

# custom the stem lines
(markers, stemlines, baseline) = plt.stem(values)
plt.setp(stemlines, linestyle="-", color="olive", linewidth=0.5 )
plt.show()

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Contact & Edit

👋 This document is a work by Yan Holtz. Any feedback is highly encouraged. You can fill an issue on Github, drop me a message onTwitter, or send an email pasting yan.holtz.data with gmail.com.

This page is just a jupyter notebook, you can edit it here. Please help me making this website better 🙏!

Violin

Density

Histogram

Boxplot

Ridgeline

Scatterplot

Heatmap

Correlogram

Bubble

Connected Scatter

2D Density

Barplot

Spider / Radar

Wordcloud

Parallel

Lollipop

Circular Barplot

Treemap

Venn Diagram

Donut

Pie Chart

Dendrogram

Circular Packing

Line chart

Area chart

Stacked Area

Streamgraph

Map

Choropleth

Hexbin

Cartogram

Connection

Bubble

Chord Diagram

Network

Sankey

Arc Diagram

Edge Bundling

Colors

Interactivity

Animation with python

Animation

Cheat sheets

Caveats

3D