fix font
This commit is contained in:
parent
adabac9750
commit
9301a9297d
@ -4,8 +4,10 @@ import pandas as pd
|
||||
import matplotlib
|
||||
matplotlib.use('Agg') # headless backend
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import font_manager
|
||||
from scipy.optimize import curve_fit
|
||||
from scipy.signal import savgol_filter as _savgol_filter
|
||||
import os
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -158,6 +160,20 @@ def calculate_large_angle_g(L, periods, gamma):
|
||||
return None
|
||||
|
||||
|
||||
# 设置中文字体
|
||||
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}, 使用系统字体")
|
||||
|
||||
|
||||
def calculate_physical_parameters(L, popt):
|
||||
"""
|
||||
从拟合参数计算物理参数
|
||||
@ -171,9 +187,6 @@ def calculate_physical_parameters(L, popt):
|
||||
return g, b_over_m, g_no_damping
|
||||
|
||||
|
||||
plt.rcParams['font.sans-serif'] = ['PingFang HK']
|
||||
|
||||
|
||||
def visualize_results(t, theta, theta_smooth, theta_fit, fitted_params, data=None, pivot=None, mm_per_pixel=None, output_path='pendulum_fit_analysis.png'):
|
||||
"""可视化实验数据和拟合结果"""
|
||||
fig = plt.figure(figsize=(12, 18))
|
||||
|
||||
BIN
app/fonts/PingFangSC-Medium.ttf
Normal file
BIN
app/fonts/PingFangSC-Medium.ttf
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user