参考博客:
https://zhuanlan.zhihu.com/p/658373265
实现1
import matplotlib.pyplot as plt
import numpy as np
# 设置圆的半径和圆心坐标
radius = 1.0
x_center, y_center = 0, 0
# 生成圆的点
theta = np.linspace(0, 2*np.pi, 100)
x = radius * np.cos(theta) + x_center
y = radius * np.sin(theta) + y_center
# 绘制圆
plt.plot(x, y, color='blue')
# 设置坐标轴的等比例显示
plt.axis('equal')
# 显示图形
plt.show()
实现2
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
# 创建一个新的图形
fig, ax = plt.subplots()
# 圆的半径和中心坐标
radius = 1
center = (0, 0)
# 绘制圆
circle = plt.Circle(center, radius, fill=False, color='blue')
# 将圆添加到图形中
ax.add_artist(circle)
# 设置坐标轴的范围和纵横比例
ax.set_xlim(-1.1 * radius, 1.1 * radius)
ax.set_ylim(-1.1 * radius, 1.1 * radius)
ax.set_aspect('equal', adjustable='box')
# 显示图形
plt.show()
画图3
from matplotlib import patches
import matplotlib.pyplot as plt
fig,ax = plt.subplots(figsize=(4,4))
radius = 1
patch = patches.Circle((0, 0), radius=radius)
ax.add_artist(patch)
ax.set_xlim(-1.1 * radius, 1.1 * radius)
ax.set_ylim(-1.1 * radius, 1.1 * radius)
plt.show()