Description of the problem
When plotting in Python using Matplotlib, I can't display the Chinese above the axes and the Chinese inside the title.
import numpy as np from matplotlib import pyplot as plt import chinesename cn = () name_list = (10) rand_numbers = ((1,11),size=10,replace=False) ('name') ('number') (name_list,rand_numbers,'ob') ()
Run the display:
Solution one:
#Solve the method of not displaying Chinese when mapping, set fonts import matplotlib ("font", family='Microsoft YaHei')
Solution two:
['-serif'] = 'SimHei'
Both methods can make Chinese display normally
Supplement:
- SimSun: Song Style; KaiTI: Regular Style; Microsoft YaHei: Microsoft Yahei
- LiSu: Official Script; FangSong: Imitation Song; Apple LiGothic Medium: Apple LiGothic Medium;
In addition, after you can display Chinese in the chart, you need to operate the display of '-', otherwise the negative sign in the data will not be displayed.
import numpy as np from matplotlib import pyplot as plt #Solve the problem of not displaying the Chinese language when mapping method one import matplotlib ("font", family='LiSu') ## The solution to the mapping does not show the Chinese method two # ['-serif'] = 'SimHei' x = (-10,10) y = x*2+5 ('diagramsY=X×2+5') ('x-value') ('y-value') (x,y) ()
Simply add the following code:
# When the font supports Chinese, you must set the minus sign, otherwise when the value of the minus sign can not be displayed ['axes.unicode_minus']=False
summarize
This article on the Python Matplotlib plotting using Matplotlib can not display the Chinese fonts of the two solutions to this article, more related Python Matplotlib plotting can not display the Chinese fonts, please search for my previous posts or continue to browse the following articles I hope that you will support me in the future more!