简体   繁体   English

围绕一个点绘制/绘制一个具有一定半径的圆(matplotlib)

[英]Drawing/plotting a circle with some radius around a point (matplotlib)

I use scatter to plot some points.我使用分散到 plot 一些点。 For example:例如:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

fig, ax = plt.subplots()
ax.scatter([1,2, 1.5], [2, 1, 1.5])
plt.show()

Now I also want a circle with radius 0.5 around point [1.5, 1.5] in the plot.现在我还想要一个半径为 0.5 的圆,围绕 plot 中的点 [1.5, 1.5]。 How do I do that?我怎么做? I know that there are edgecolors, so that I could just set them to 'none' and then to some color.我知道有边缘颜色,所以我可以将它们设置为“无”,然后设置为某种颜色。 But those circles then have no radius of 0.5.但是这些圆的半径没有 0.5。

To make a circle around point, you can use plt.Circle as shown below:要围绕点做一个圆圈,您可以使用 plt.Circle 如下所示:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
ax.scatter([1,2, 1.5], [2, 1, 1.5])
cir = plt.Circle((1.5, 1.5), 0.07, color='r',fill=False)
ax.set_aspect('equal', adjustable='datalim')
ax.add_patch(cir)
plt.show()

I hope this solved your problem.我希望这能解决你的问题。 And please let me know further.请让我进一步了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM