Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert a dot at a certain point on a line with matplotlib

I wish to know how to insert a dot (or some kind of marker) at a distinct point on a curve/line in matplotlib. Using the tutorial documentation, http://matplotlib.org/users/pyplot_tutorial.html

we plot

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16])
plt.axis([0, 6, 0, 20])
plt.show()

enter image description here

Now, I know how to transform this line into a series of points, here using red dots 'ro':

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro')
plt.axis([0, 6, 0, 20])
plt.show()

enter image description here

How can I add a "dot" at a distinct point? For example, add a dot at point [3,9]?

like image 374
ShanZhengYang Avatar asked Jul 19 '15 14:07

ShanZhengYang


People also ask

How do I circle a point in matplotlib?

Plot the data and data points using plot() method. Set X and Y axes scale. To put a circled marker, use the plot() method with marker='o' and some properties. Annotate that circle (Step 7) with arrow style.


1 Answers

You can call plt.plot(x, y, 'style') again, like:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4], [1,4,9,16], 'ro') # Your original list
plt.plot(5, 25, 'go')                 # Additional point
plt.plot(6, 36, 'yo')                 # Additional point
plt.axis([0, 10, 0, 40])              # Modified axis
plt.show()

Result of running the program

like image 77
Robert Lacher Avatar answered Oct 08 '22 14:10

Robert Lacher