0
0
Matplotlibdata~5 mins

Marker size variation in Matplotlib

Choose your learning style9 modes available
Introduction

Changing marker size helps show differences in data points clearly on a plot.

You want to highlight important points by making them bigger.
You want to show a third variable using size in a scatter plot.
You want to make a plot easier to read by adjusting marker sizes.
You want to compare groups with different marker sizes.
You want to add style and clarity to your data visualization.
Syntax
Matplotlib
plt.scatter(x, y, s=size_values)

# or
plt.plot(x, y, marker='o', markersize=size_value)

s in plt.scatter controls marker size and can be a single number or a list of sizes.

markersize in plt.plot sets the size of markers when using line plots.

Examples
All markers have the same size 100.
Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [4, 5, 6]
plt.scatter(x, y, s=100)
plt.show()
Markers have different sizes from the list.
Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [4, 5, 6]
sizes = [20, 50, 200]
plt.scatter(x, y, s=sizes)
plt.show()
Using plt.plot with marker size 15.
Matplotlib
import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [4, 5, 6]
plt.plot(x, y, marker='o', markersize=15)
plt.show()
Sample Program

This code creates a scatter plot where each point's size shows its importance or value. Bigger points stand out more.

Matplotlib
import matplotlib.pyplot as plt

# Data points
x = [1, 2, 3, 4, 5]
y = [5, 7, 4, 6, 8]

# Sizes represent importance or value
sizes = [50, 200, 100, 300, 150]

plt.scatter(x, y, s=sizes, color='blue', alpha=0.6)
plt.title('Scatter plot with marker size variation')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()
OutputSuccess
Important Notes

Marker size s in plt.scatter is in points squared, so 100 means 10x10 points.

Use alpha to make markers transparent if they overlap.

Marker size can help show extra data dimension visually.

Summary

Marker size changes how big points look on a plot.

You can use a single size or a list of sizes for different points.

It helps add meaning and clarity to your charts.