How do I add a small filled circle or point to a countour plot in matplotlib?
1 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()

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()

4 Comments
unutbu
Let's take it line-by-line. What's the first line that doesn't make sense?
praxmon
F = X ** Y G = Y ** X This is the oneunutbu
X and Y are NumPy arrays of shape (100, 100). ** is the exponentiation operator. Arithmetic operations on NumPy arrays are performed element-wise. So X ** Y is the exponentiation of X to the Yth power, done for each element in X with the corresponding element in Y. Try it out in a Python interpreter, perhaps with smaller arrays for X and Y so the result is easier to see.unutbu
The plot is showing the roots of the equation
x^y = y^x. These is the obvious solution, the straight line x = y. But then there is also that curved line, shown above.