| 1 | import matplotlib.pyplot as plt |
| 2 | import matplotlib.font_manager as fm |
| 3 | |
| 4 | # 设置中文字体 |
| 5 | plt.rcParams['font.sans-serif'] = ['SimHei'] # 使用黑体 |
| 6 | plt.rcParams['axes.unicode_minus'] = False # 解决负号显示问题 |
| 7 | |
| 8 | # 示例数据 |
| 9 | x = [1, 2, 3, 4] |
| 10 | y = [10, 20, 15, 25] |
| 11 | |
| 12 | plt.plot(x, y, label="示例数据") |
| 13 | plt.xlabel("时间") |
| 14 | plt.ylabel("值") |
| 15 | plt.title("示例图表") |
| 16 | plt.legend() |
| 17 | |
| 18 | # 显示图表 |
| 19 | plt.show() |
| 20 |
LiuShen / 解决Matplotlib不显示汉字的问题
Last active 4 months ago
解决Matplotlib不显示汉字的问题,设置汉语字体
Revision d29bb81cb489b0e201370013c9faef08f71eb00f