fix font
This commit is contained in:
parent
9301a9297d
commit
61b00ead1a
@ -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
26
app/fonts/README.md
Normal 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
|
||||
...
|
||||
```
|
||||
Loading…
x
Reference in New Issue
Block a user