matplotlib中文宋体,西文新罗马
matplotlib中文宋体,西文新罗马
import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib import font_manager# 设置全局字体,西文优先用 Times New Roman,中文优先用宋体
rcParams['font.family'] = ['Times New Roman', 'SimSun'] # SimSun 是宋体plt.figure()
# 中英文混排,matplotlib 会自动 fallback
plt.title("Matplotlib 示例 Example", fontsize=16)
# 强制中文部分用宋体
plt.xlabel("时间 (Time)", fontsize=14)
# 强制英文部分用 Times New Roman
plt.ylabel("Value", fontsize=14)
plt.plot([0, 1], [0, 1], label="线性 Linear")
plt.legend()
plt.show()