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;否則無法顯示負號。並將前面的 # 注釋號去掉。

 看完點個關注唄!!(總結不易)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM