How to use different markers for different points in a Pylab scatter plot(Matplotlib)?

To use different markers for different points in a Pylab (Pyplot) scatter plot, you can assign unique markers to each data point. This technique is useful for distinguishing between different categories or highlighting specific points in your visualization.

Basic Approach

The key steps are ?

  • Set the figure size and adjust the padding between and around the subplots
  • Initialize variables for sample data
  • Create x and y data points
  • Make a list of different markers
  • Zip the coordinates with markers and plot each point individually
  • Display the figure using show() method

Example

Here's how to create a scatter plot with different markers for each point ?

import numpy as np
import matplotlib.pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

N = 10
x = np.random.rand(N)
y = np.random.rand(N)

markers = ["d", "v", "s", "*", "^", "d", "v", "s", "*", "^"]

for xp, yp, m in zip(x, y, markers):
    plt.scatter(xp, yp, marker=m, s=50)

plt.title("Scatter Plot with Different Markers")
plt.xlabel("X values")
plt.ylabel("Y values")
plt.show()

Using Colors with Different Markers

You can also combine different markers with different colors for better visualization ?

import numpy as np
import matplotlib.pyplot as plt

# Generate data
N = 8
x = np.random.rand(N)
y = np.random.rand(N)

markers = ["o", "s", "^", "v", "<", ">", "p", "*"]
colors = ["red", "blue", "green", "orange", "purple", "brown", "pink", "gray"]

for i, (xp, yp) in enumerate(zip(x, y)):
    plt.scatter(xp, yp, marker=markers[i], c=colors[i], s=100)

plt.title("Scatter Plot with Different Markers and Colors")
plt.xlabel("X values")
plt.ylabel("Y values")
plt.grid(True, alpha=0.3)
plt.show()

Common Marker Types

Here are some popular marker options you can use ?

Marker Symbol Description
"o" ? Circle
"s" ? Square
"^" ? Triangle up
"v" ? Triangle down
"*" * Star
"d" ? Diamond

Conclusion

Using different markers in scatter plots helps distinguish between data categories and makes visualizations more informative. Combine markers with colors and appropriate sizing for even better clarity in your data presentations.

Updated on: 2026-03-26T00:05:02+05:30

8K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements