matplotlib:在绘图中添加圆圈

时间:2010-08-09 11:44:38

标签: python matplotlib

如何在matplotlib中添加一个小的实心圆或点到等高线图?

1 个答案:

答案 0 :(得分:36)

以下是一个示例,使用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

来自文档的here is another example(虽然不是轮廓图)。

或者,您可以使用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