在Python中,可以利用matplotlb库的“Circle()”来画圆,将其封装到plot_circle函数中调用即可画圆。方法是:1、利用figure确定画布大小;2、利用“Circle()”配置圆的相关信息。
代码如下:from matplotlib.patches import Ellipse, Circle
import matplotlib.pyplot as plt
def plot_cicle():
fig = plt.figure()
ax = fig.add_subplot(111)
cir1 = Circle(xy = (0.0, 0.0), radius=2, alpha=0.5)
ax.add_patch(cir1)
x, y = 0, 0
ax.plot(x, y, 'ro')
plt.axis('scaled')
plt.axis('equal') #changes limits of x or y axis so that equal increments of x and y have the same length
plt.show()
plot_cicle()