Lollipop chart

A lollipop chart, also known as a lollipop plot or a dot plot with lines, is a type of graph used to display and compare values between different categories. It combines elements of both bar charts and scatter plots. The chart consists of markers (usually circles) representing the data points plotted on a horizontal axis, and each marker is connected to a vertical line or stem. The length of the line indicates the value associated with the data point.

Here's a step-by-step explanation of how to interpret a lollipop chart:

1. Categories: The horizontal axis represents the categories or groups being compared. It could be anything from different products, cities, or time periods.

2. Data Points: Each category has a corresponding data point represented by a circle marker on the horizontal axis. The position of the marker along the axis indicates the category it belongs to.

3. Values: The vertical axis represents the values associated with the data points. The scale on the vertical axis varies depending on the range of values being represented.

4. Lines or Stems: A vertical line or stem connects the data point (circle marker) to the corresponding value on the vertical axis. The length of the line indicates the magnitude or size of the value.

Lollipop charts are particularly useful when you want to highlight and compare values within different categories. They provide a clear visual representation of the data points while emphasizing the differences in values using the length of the lines. Additionally, lollipop charts can be easily customized with additional features such as color-coding, labels, or tooltips to enhance the clarity and interpretation of the data.

Python Example

import matplotlib.pyplot as plt import numpy as np # Sample data categories = ['Category A', 'Category B', 'Category C', 'Category D'] values = [15, 10, 7, 12] # Create a figure and axis fig, ax = plt.subplots() # Plot the lollipop chart ax.vlines(categories, ymin=0, ymax=values, color='skyblue', linewidth=3) ax.scatter(categories, values, color='blue', s=100, zorder=10) # Set labels and title ax.set_xlabel('Categories') ax.set_ylabel('Values') ax.set_title('Lollipop Chart') # Rotate category labels if needed plt.xticks(rotation=45) # Show the chart plt.show()

In this example, we have a list of categories (categories) and their corresponding values (values). We create a figure and an axis using plt.subplots(). Then, we use ax.vlines() to draw the vertical lines (stems) from the horizontal axis to the values, and ax.scatter() to plot the circle markers. The colors, line widths, and marker sizes can be customized as per your preference.

Finally, we set the labels for the x-axis, y-axis, and title using ax.set_xlabel(), ax.set_ylabel(), and ax.set_title(), respectively. If the category labels are too long and overlap, you can rotate them using plt.xticks(rotation=45) or adjust the rotation angle as needed.

lollipop chart result