程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

The solution to the problem of not displaying Chinese in Python drawing

編輯:Python

Catalog

Preface

One 、plt.title Chinese display solution :

Two 、plt.plot Chinese display solution :

3、 ... and 、 Code for reference

summary

Preface

python drawing , If it is displayed in English, there is basically no problem , But Chinese may be garbled or not displayed .

After personal testing , The following figure “ The horizontal axis ”,“ The vertical axis ” There is no big problem with the Chinese display of the words , Mainly plt.title Part and plt.plot Partial display
 

One 、plt.title Chinese display solution :from matplotlib.font_manager import FontPropertiesfont_set = FontProperties(fname=r"c:\windows\fonts\SIMLI.TTF", size=15)plt.title(u' Xiao Ming's title ', FontProperties=font_set)

FontProperties The local fonts are loaded in

route :C:\Windows\Fonts

Select the right mouse button attribute of the font to copy the name for replacement

font_set = FontProperties(fname=r"c:\windows\fonts\SIMLI.TTF", size=15)

From the result of changing the font , The horizontal and vertical coordinates and the title area are affected ,plt.plot Unaffected

Two 、plt.plot Chinese display solution :

Similar to the above , Add the following line

plt.legend(prop={'family':'SimHei','size':15}) 3、 ... and 、 Code for reference from matplotlib import pyplotimport matplotlib.pyplot as pltfrom matplotlib.font_manager import FontPropertiesfrom matplotlib.ticker import MultipleLocator, FormatStrFormatter font_set = FontProperties(fname=r"c:\windows\fonts\simsun.ttc", size=15)import matplotlibimport numpy as np%matplotlib inlineplt.rcParams['figure.figsize'] = (12.0, 8.0) # set default size of plotsplt.rcParams['image.interpolation'] = 'nearest'plt.rcParams['image.cmap'] = 'gray'# plt.rcParams['font.sans-serif']=['SimHei']# plt.rcParams['axes.unicode_minus']=False # Set the title size plt.rcParams['font.size'] = '16'fig = plt.figure()matplotlib.rcParams.update({'text.usetex': False,'font.family': 'stixgeneral','mathtext.fontset': 'stix',})# myfont = FontProperties(fname='/homenuxidc/.local/fonts/ WenQuanYi is in the dark .ttf')x = range(0,102,2)x = [str(x) for x in list(x)]x = range(len(x))# Here, if you get the value , It is better to omit , Otherwise, there is too much redundant code dj1=[0.140885022563663,0.285128051316358,0.331236115292078,0.372582750937596,0.463174450139405,0.586773503380428,0.542598182149781,0.542598182149781,0.564956686389027,0.542598182149781,0.519630577568173,0.428649426296771,0.676284101462148,0.635875231620977,0.564956686389027,0.542598182149781,0.564956686389027,0.62899995822798,0.676284101462148,0.721874028834649,0.676284101462148,0.702515362688485,0.682890636232397,0.557567115066442,0.564956686389027,0.635875231620977,0.656252254277025,0.676284101462148,0.721874028834649,0.62899995822798,0.62899995822798,0.702515362688485,0.759939881400332,0.702515362688485,0.696005029828444,0.656252254277025,0.696005029828444,0.676284101462148,0.608105164606941,0.741002175030875,0.721874028834649,0.702515362688485,0.721874028834649,0.62899995822798,0.608105164606941,0.682890636232397,0.676284101462148,0.702515362688485,0.696005029828444,0.696005029828444,0.696005029828444]plt.plot(x, dj1,marker='s',label=u' Xiao Ming ')plt.grid(linestyle='--') plt.grid(axis="x")plt.title(u'SimHei', fontproperties=font_set)plt.title(' Xiao Ming's title ')plt.legend() # Let the legend work y_major_locator=MultipleLocator(0.1)ax=plt.gca()ax.yaxis.set_major_locator(y_major_locator)plt.ylim(0,1)plt.xlim(0,55)plt.margins(0)plt.subplots_adjust(bottom=0.001)plt.xlabel(" The horizontal axis ",fontproperties=font_set) #X Axis labels plt.ylabel(" The vertical axis ",fontproperties=font_set) #Y Axis labels plt.legend(prop={'family':'SimHei','size':15}) summary

This is about python This is the end of the article on how to solve the problem of drawing Chinese without displaying , More about python Please search the previous articles of the software development network or continue to browse the relevant articles below. I hope you will support the software development network in the future !



  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved