Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib: add circle to plot

Tags:

How do I add a small filled circle or point to a countour plot in matplotlib?

like image 635
Neil G Avatar asked Aug 09 '10 11:08

Neil G


People also ask

How do you graph a circle function in Python?

You can easily draw the circle directly. Given 0 = x1**2 + x**2 - 0.6 it follows that x2 = sqrt(0.6 - x1**2) (as Dux stated). But what you really want to do is to transform your cartesian coordinates to polar ones. if you use these substitions in the circle equation you will see that r=sqrt(0.6) .

How do you plot a quarter circle in Python?

The pattern you are showing is in basic is 4 semi circles rotated 90 degrees clockwise. You can draw a semi circle by setting a limit for the equation x^2 + y^2 - 1 such that it produces a semi circle.


1 Answers

Here is an example, using pylab.Circle:

import numpy as np import matplotlib.pyplot as plt  e = np.e X, Y = np.meshgrid(np.linspace(0, 5, 100), np.linspace(0, 5, 100)) F = X ** Y G = Y ** X  fig = plt.figure() ax = fig.add_subplot(1, 1, 1) circ = plt.Circle((e, e), radius=0.07, color='g') plt.contour(X, Y, (F - G), [0]) ax.add_patch(circ) plt.show() 

enter image description here

And here is another example (though not a contour plot) from the docs.

Or, you could just use plot:

import numpy as np import matplotlib.pyplot as plt  e = np.e X, Y = np.meshgrid(np.linspace(0, 5, 100), np.linspace(0, 5, 100)) F = X ** Y G = Y ** X  fig = plt.figure() ax = fig.add_subplot(1, 1, 1) plt.contour(X, Y, (F - G), [0]) plt.plot([e], [e], 'g.', markersize=20.0) plt.show() 

enter image description here

like image 66
unutbu Avatar answered Oct 13 '22 21:10

unutbu