This commit is contained in:
feie9456 2025-08-10 11:00:20 +08:00
parent 9301a9297d
commit 61b00ead1a
2 changed files with 38 additions and 11 deletions

View File

@ -161,19 +161,20 @@ def calculate_large_angle_g(L, periods, gamma):
# 设置中文字体
font_path = './fonts/PingFangSC-Medium.ttf'
if os.path.exists(font_path):
prop = font_manager.FontProperties(fname=font_path)
plt.rcParams['font.family'] = prop.get_name()
plt.rcParams['axes.unicode_minus'] = False
logger.info(f"成功加载字体文件: {font_path}")
else:
# 备选方案
plt.rcParams['font.sans-serif'] = ['PingFang SC', 'SimHei', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False
logger.warning(f"字体文件不存在: {font_path}, 使用系统字体")
font_path = os.path.join(os.path.dirname(__file__), 'fonts', 'PingFangSC-Medium.ttf')
# 方法1通过FontProperties直接设置
from matplotlib.font_manager import FontProperties
chinese_font = FontProperties(fname=font_path)
# 将字体添加到matplotlib的字体管理器
font_manager.fontManager.addfont(font_path)
# 设置默认字体
plt.rcParams['font.family'] = chinese_font.get_name()
plt.rcParams['axes.unicode_minus'] = False
def calculate_physical_parameters(L, popt):
"""
从拟合参数计算物理参数

26
app/fonts/README.md Normal file
View File

@ -0,0 +1,26 @@
# 字体文件说明
请将 `PingFangSC-Medium.ttf` 字体文件放置在此目录下。
## 如何获取字体文件:
1. **从 macOS 系统复制**
```bash
cp "/System/Library/Fonts/PingFang.ttc" ./PingFangSC-Medium.ttf
```
2. **从网上下载**
- 搜索并下载 PingFang SC 字体
- 或者使用其他中文字体如 Noto Sans CJK
3. **使用其他字体**
如果要使用其他字体,请修改 `analysis.py` 中的字体文件名。
## 目录结构:
```
app/
fonts/
PingFangSC-Medium.ttf # 字体文件应放在这里
analysis.py
...
```