Python matplotlib:添加圆圈以绘制

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3439639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 11:07:10  来源:igfitidea点击:

matplotlib: add circle to plot

pythonmatplotlib

提问by Neil G

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

如何在 matplotlib 中添加一个小的实心圆或指向一个计数图?

采纳答案by unutbu

Here is an example, using pylab.Circle:

这是一个使用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:

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

在此处输入图片说明