You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python matplotlib实现单位圆内5π/6角度圆弧绘制与LaTeX标注

实现方法

直接使用matplotlib内置的Arc补丁绘制圆内的角度标记弧即可,不需要手动计算弧上所有点位。注意Arc的角度参数使用角度制而非弧度,文本标注原生支持LaTeX语法渲染数学公式。

核心实现步骤

  • 从matplotlib.patches导入Arc类
  • 绘制内部圆弧:设置圆弧中心在原点(0,0),半径取小于1的值(比如0.4,保证在单位圆内部),圆弧起始角度为0°(对应x轴正方向的角初始边),终止角度为150°(即$5\pi/6$对应的角度值)
  • 在圆弧中点位置添加角度标注,使用LaTeX语法编写角度公式

修改后可直接运行的完整代码

import numpy as np
import matplotlib.pyplot as plt
import sympy as syp
from matplotlib.patches import Arc

# 绘制单位圆
angle = np.linspace(0, 2*np.pi, 150)
radius = 1
x = radius * np.cos(angle)
y = radius * np.sin(angle)

figure, axes = plt.subplots(1)
plt.ylim(-1, 1.5) # 调整y轴范围适配标注,去掉原范围多余留白
plt.xlim(-1.5, 1.5) # 调整x轴范围保证第二象限内容完整显示
axes.plot(x, y)
plt.plot([-1, 1], [0, 0], color='black') # x轴
plt.plot([0, 0], [-1, 1], color="red") # y轴
plt.plot([-syp.sqrt(3)/2, 0], [1/2, 0], "green") # 5π/6终边
axes.set_aspect(1) # 锁定坐标轴等比例,避免圆变形

# 绘制内部角度圆弧
arc_radius = 0.4
angle_arc = Arc(
    xy=(0, 0), # 圆弧中心与原点重合
    width=2*arc_radius, # Arc参数为外接矩形宽度,即2倍半径
    height=2*arc_radius,
    angle=0, # 圆弧不额外旋转
    theta1=0, # 起始角度:x轴正方向,单位为角度
    theta2=150, # 终止角度:5π/6 = 150°,单位为角度
    color='orange',
    linewidth=2
)
axes.add_patch(angle_arc)

# 添加角度标注,位置在圆弧中点外侧
label_radius = 0.55
mid_angle = 5*np.pi/12 # 0和5π/6的中点角度
label_x = label_radius * np.cos(mid_angle)
label_y = label_radius * np.sin(mid_angle)
plt.text(
    label_x, label_y,
    r'$\theta = \frac{5\pi}{6}$',
    fontsize=14,
    ha='center',
    va='center'
)

plt.title('Reference Angles')
plt.show()

效果说明

  • 橙色圆弧即为需要的$5\pi/6$角度标记,半径0.4完全落在单位圆内部
  • 标注自动渲染LaTeX格式的分数和π符号,位置在圆弧外侧不会遮挡线条
  • 调整后的坐标轴范围去掉了原代码中多余的留白,图形显示更紧凑

内容的提问来源于stack exchange,提问作者Trig

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.29 13:36:22