国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python中matplotlib中文亂碼解決辦法

2020-01-04 17:09:56
字體:
來源:轉載
供稿:網友

Matplotlib是Python的一個很好的繪圖包,但是其本身并不支持中文(貌似其默認配置中沒有中文字體),所以如果繪圖中出現了中文,就會出現亂碼。

python/267132.html">matplotlib繪制圖像有中文標注時會有亂碼問題。

matplotlib,中文亂碼,亂碼,python

實例代碼:

import matplotlibimport matplotlib.pyplot as plt#定義文本框和箭頭格式decisionNode =dict(boxstyle="sawtooth",fc="0.8")leafNode=dict(boxstyle="round4",fc="0.8")arrow_args=dict(arrowstyle="<-")#繪制帶箭頭的注解def plotNode(nodeTxt,centerPt,parentPt,nodeType):  createPlot.axl.annotate(nodeTxt,xy=parentPt,xycoords='axes fraction',xytext=centerPt,textcoords='axes fraction',va="center",ha="center",bbox=nodeType,arrowprops=arrow_args)def createPlot():  fig =plt.figure(1,facecolor='white')  fig.clf()  createPlot.axl=plt.subplot(111,frameon=False)  plotNode(U'決策點',(0.5,0.1),(0.1,0.5),decisionNode)  plotNode(U'葉節點',(0.8,0.1),(0.3,0.8),leafNode)  plt.show()

解決辦法:代碼中引入字體

import matplotlib.pyplot as pltimport matplotlib#定義自定義字體,文件名是系統中文字體myfont = matplotlib.font_manager.FontProperties(fname='C:/Windows/Fonts/simkai.ttf') #解決負號'-'顯示為方塊的問題 matplotlib.rcParams['axes.unicode_minus']=False decisionNode =dict(boxstyle="sawtooth",fc="0.8")leafNode=dict(boxstyle="round4",fc="0.8")arrow_args=dict(arrowstyle="<-")def plotNode(nodeTxt,centerPt,parentPt,nodeType):  createPlot.axl.annotate(nodeTxt,xy=parentPt,xycoords='axes fraction',xytext=centerPt,textcoords='axes fraction',va="center",ha="center",bbox=nodeType,arrowprops=arrow_args,fontproperties=myfont)def createPlot():  fig =plt.figure(1,facecolor='white')  fig.clf()  createPlot.axl=plt.subplot(111,frameon=False)  plotNode(U'決策點',(0.5,0.1),(0.1,0.5),decisionNode)  plotNode(U'葉節點',(0.8,0.1),(0.3,0.8),leafNode)  plt.show()

matplotlib,中文亂碼,亂碼,python

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙江县| 泰安市| 垣曲县| 东方市| 奎屯市| 钦州市| 轮台县| 枣强县| 正蓝旗| 万宁市| 开封市| 南和县| 旬阳县| 长海县| 萍乡市| 忻州市| 商水县| 外汇| 昭觉县| 西乌珠穆沁旗| 收藏| 鲁山县| 台东县| 滨海县| 雷波县| 拉萨市| 司法| 玛纳斯县| 天长市| 西藏| 永清县| 兴隆县| 右玉县| 云龙县| 西林县| 宣城市| 蓬安县| 达拉特旗| 遵义市| 北川| 全南县|