matplotlib: add circle to plot


Question

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

1
23
8/9/2010 11:44:38 AM

Accepted Answer

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

36
2/1/2013 2:03:47 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon