matplotlib画圆

参考博客:
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()

在这里插入图片描述

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值