用matplotlib画圆


# -*- coding:utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt

print(np.pi)
def circle(x,y,r,color='k',count=1000):
    xarr=[]
    yarr=[]
    for i in range(count):
        j = float(i)/count * 2 * np.pi
        xarr.append(x+r*np.cos(j))
        yarr.append(y+r*np.sin(j))
    plt.plot(xarr,yarr,c=color)

fig1 = plt.figure(num='fig1',figsize=(6,6),dpi=100,facecolor='#FFFFFF',edgecolor='#FF0000')
max_x=600
max_y=600
plt.xlim(0,max_x)
plt.ylim(0,max_y)

#N = input('Please input a number:')
cc = ['r','g','b','m','y','c']

for cent_x in [max_x / 4,max_x/4 * 3]:
    for cent_y in [max_y / 4,max_y/4 * 3]:
        for r in range(8,250,5):
            circle(cent_x,cent_y, r,cc[r%len(cc)])

plt.show()
plt.close()

运行结果:


猜你喜欢

转载自blog.csdn.net/zjyklwg/article/details/79491418