Saturday, September 27, 2025
HomeLanguagesHow to Add Markers to a Graph Plot in Matplotlib with Python?

How to Add Markers to a Graph Plot in Matplotlib with Python?

In this article, we will learn how to add markers to a Graph Plot in Matplotlib with Python. For that just see some concepts that we will use in our work.

  • Graph Plot: A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variables.
  • Markers: The markers are shown in graphs with different shapes and colors to modify the meaning of the graph.

Example 1: Add Square Markers to a Graph Plot in Matplotlib 

Python3




# importing packages
import matplotlib.pyplot as plt
 
# plot with marker
plt.plot([2, 8, 7, 4, 7, 6, 2, 5, 9], marker='D')
plt.show()


Output :

Add Markers to a Graph Plot in Matplotlib

 

Example 2: Add Triangle Markers to a Graph Plot in Matplotlib

Python3




# importing packages
import matplotlib.pyplot as plt
 
# create data
t = np.arange(0., 5., 0.2)
 
# plot with marker
plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^')
plt.show()


Output :

Add Markers to a Graph Plot in Matplotlib

 

Example 3: Add Circle Markers to a Graph Plot in Matplotlib

Python3




# importing packages
import matplotlib.pyplot as plt
import numpy as np
 
# create data
x_values = np.linspace(0, 10, 20)
y_values = np.sin(x_values)
markers = ['>', '+', '.', ',', 'o', 'v', 'x', 'X', 'D', '|']
 
# apply markers
for i in range(20):
    plt.plot(x_values, y_values + i*0.2, markers[i % 10])
plt.show()


Output :

Add Markers to a Graph Plot in Matplotlib

 

RELATED ARTICLES

Most Popular

Dominic
32323 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6690 POSTS0 COMMENTS
Nicole Veronica
11857 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11913 POSTS0 COMMENTS
Shaida Kate Naidoo
6807 POSTS0 COMMENTS
Ted Musemwa
7073 POSTS0 COMMENTS
Thapelo Manthata
6763 POSTS0 COMMENTS
Umr Jansen
6768 POSTS0 COMMENTS