python 随机生成N个坐标,并画随机大小的圆

python 随机生成N个坐标,并画随机大小的圆

import matplotlib.pyplot as plt 
import numpy as np 


# plt.plot(x, y, '+')
# plt.show()


class Circle:

    def __init__(self,r1=0,x0=0,y0=0):
        self.r = r1
        self.x = x0 
        self.y = y0
    # 方法,画圆
    def pint(self):
       # 创建一个空白窗体
        # plt.title('Circle')
        # plt.xlabel('x')
        # plt.ylabel('y')
        # 点的横坐标为a
        a = np.arange(x-r,x+r,0.01)
        # 点的纵坐标为b
        b1 = np.sqrt(np.power(self.r,2)-np.power((a-self.x),2))+self.y
        b2 = -np.sqrt(np.power(self.r,2)-np.power((a-self.x),2))+self.y

        #plt.plot(a,b1,color='r',linestyle='-')
        #plt.plot(a,b2,color='r',linestyle='-')
        plt.fill_between(a, b2, b1, facecolor='black')
        # plt.scatter(self.x,self.y,c='c',marker='+')
        plt.axis([-10,310,-10,310])
        # plt.grid(True)
        
N = 200





X = np.random.rand(1, N)*300
X = X.flatten()
Y = np.random.rand(1, N)*300
Y = Y.flatten()
R = np.random.rand(1, N)*5 + 1
R = R.flatten()

plt.figure(figsize=(5,5)) 
for (r, x, y) in zip(R, X, Y):
    #print(r, x, y)
    Circle(r, x, y).pint()
plt.show()




你可能感兴趣的:(sci科研数据作图,python)