bhylu.com

Advertisements

Matplotlib Markers

Markers show individual observations on a plotted series. They can make a sparse line chart easier to read and distinguish from another series.

Understand the idea

Choose a marker and size that remain clear at the final image size. Too many large markers on dense data can hide the underlying trend. Use shape as well as colour when a distinction matters, so the chart remains understandable in grayscale or to readers with colour-vision differences.

Where to try it

Run this complete script in a local virtual environment with Matplotlib installed (py -m pip install matplotlib). It uses a non-interactive backend and saves workshop.png in the current folder. The site shows a rendered example below; its text-only online runner does not display plot windows.

A worked example

Python

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(7, 4), layout="constrained")
ax.plot([1, 2, 3, 4], [4, 7, 6, 9], marker="s", markersize=7)
ax.set(xlabel="Week", ylabel="Bookings", title="Show every observation")
fig.savefig("workshop.png", dpi=140)
plt.close(fig)
print("Saved workshop.png")

Read the result

Square markers reveal the four exact observations along the connecting line.

Square markers reveal the four exact observations along the connecting line.
Rendered from this original example. Change and rerun the script locally to make your own chart.

Try one change

Compare circles and squares at two sizes, checking readability in a small exported image.

For package options, see the Matplotlib documentation.