plt.xlabel()无法显示中文

1.全局设置中文字体

from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']   # 雅黑字体
plt.scatter(data.Education,data.Income)
plt.xlabel("受教育年限")
plt.ylabel("工资")
plt.show()

2.修改源文件

  • 在 python 安装目录中找到配置文件: %Python_Home%\Lib\site-packages\matplotlib\mpl-data\matplotlibrc

    (本人在D:\SoftWare\Anaconda\Lib\site-packages\matplotlib\mpl-data),用任意文本编辑器打开。

  • 找到139 行的font.family : sans-serif 将其前面的 # 注释号去掉。
  • 找到 151 行的 font.sans-serif :AR PL UMing CN, SimHei, Bitstream Vera Sans, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif 将【AR PL UMing CN, SimHei】添加在最前面,其中 AR PL UMing CN 代表:宋体。SimHei 代表:黑体。并将前面的 # 注释号去掉,重启编辑器后,便可显示中文了。
  • 同时需要更改 264 行的 axes.unicode_minus : False;使其值为 False;否则无法显示负号。并将前面的 # 注释号去掉。

 看完点个关注呗!!(总结不易)

posted @ 2021-10-18 09:26  多发Paper哈  阅读(899)  评论(0编辑  收藏  举报
Live2D