在python中绘制一个带有一些彩色点的圆圈

时间:2017-11-01 19:26:06

标签: python plot

我想绘制一个具有指定中心位置和半径的圆,并在[0-500]之间绘制100个随机点,其中80%在圆圈中,20%在不同颜色周围。 为了解决这个问题,我使用Plot circle that contains 80% (x, y) points并根据我的要求进行了自定义,但它无法正常工作。

import numpy as np
import matplotlib.pyplot as plt
n = 100
low = 0
high = 500
x = np.random.random_integers(low, high, n)
y = np.random.random_integers(low, high, n) 
x0 = y0 = 250
r = 200
#t = 80 # percent
#r0 = np.percentile(r, t)
plt.plot(x, y, '.')
circle = plt.Circle((x0, y0), r, color='black', fill=False, linestyle='--')
plt.plot(x0, y0, color='black', marker='^')
plt.gca().add_artist(circle)
plt.axis([0, 500, 0, 500])
plt.show()

1 个答案:

答案 0 :(得分:0)

我找到了问题的答案。 我们可以使用圆的方程来检查圆是否在圆中。

(x-x0)**2+(y-y0)**2 < r**2
center:(x0, y0)
radius:r