Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add markers in graph using python as shown below?

I want to design a graph like below, but, I don't know- how to add markers like the one shown in the graph. Can somebody help me with this?

For plotting a graph, I am using matplotlib package in python.

enter image description here

like image 444
Akshay Avatar asked Dec 06 '25 19:12

Akshay


1 Answers

From matplotlib doc Annotations you can modify the example with the code

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

t = np.arange(0.0, 5.0, 0.01)
s = np.cos(2*np.pi*t)
line, = ax.plot(t, s, lw=2)



ax.plot(2, 1, marker = "v", color='blue', fillstyle='none')
bbox_props = dict(boxstyle="square,pad=0.3", fc="white", ec="black", lw=1.2)
t = ax.annotate('local max\n x = 2, y = 1', xy=(2, 1), xytext=(3, 1.5),
        arrowprops=dict(arrowstyle="-", facecolor='black'), bbox=bbox_props,
        )

ax.set_ylim(-2, 2)
plt.show()

enter image description here

like image 73
Jacob Fuchs Avatar answered Dec 09 '25 10:12

Jacob Fuchs