import matplotlib.pyplot as plt
from matplotlib import rcParams
# 设置中文字体(以 macOS 系统为例,使用 'PingFang' 字体)
from matplotlib import font_manager as fm
font_path = '/System/Library/Fonts/PingFang.ttc' # 替换为实际路径
rcParams['font.family'] = fm.FontProperties(fname=font_path).get_name()
# rcParams['font.family'] = 'PingFang' # 替换为系统内可用的中文字体
# 示例数据
x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
# 创建折线图
plt.plot(x, y, marker='o', linestyle='-', color='b')
# 设置标题和标签
plt.title('示例折线图')
plt.xlabel('X 轴')
plt.ylabel('Y 轴')
# 显示网格
plt.grid(True)
# 显示图表
plt.show()