Python3 uses matplotlib paint, because Python3 uses Unicode encoding by default, so writing code is no longer required to write Plt.xlabel (U ' number of people '), but to write Plt.xlabel directly (' number ').
Attention:
In the Chinese language to add Chinese-related fonts, or because there is no font display box, because the default use of the font is not in Chinese, use examples are as follows:
#-*-coding:utf-8-*-ImportPandas as PDImportNumPy as NP fromPandasImportSeries,dataframeImportMatplotlib.pyplot as Plt fromPylabImport*Data_train=pd.read_csv (".. /train.csv")Fig=plt.figure () fig.set (Alpha=0.6)#Plt.subplot2grid ((2,3) (0,0))Data_train. Survived.value_counts (). Plot (kind="Bar")#prevent Chinese garbled characterszhfont1 = Matplotlib.font_manager. Fontproperties (fname= ' C:\WINDOWS\FONTS\SIMSUN.TTC ' )Plt.title ("rescued situation (1 for rescue)",fontproperties= zhfont1) Plt.ylabel ("number",fontproperties= zhfont1) plt.show ()
The above shaded parts are essential and the effect is:
Python3 using Matplotlib to draw Chinese garbled characters