# -*- coding:utf-8 -*- import matplotlib.pyplot as plt plt.style.use('ggplot') from matplotlib.font_manager import * import numpy as np import pandas as pd #定义自定义字体 myfont = FontProperties(fname='/temp/msyh.ttf') #解决负号'-'显示为方块的问题 plt.rcParams['axes.unicode_minus']=False df = pd.read_csv('/temp/iris.data',names=['花萼长度', '花萼宽度', '花瓣长度', '花瓣宽度', '类别']) fig,ax = plt.subplots(figsize=(6,6)) ax.plot(df['花瓣长度'], color='green') ax.set_xlabel(u'样本号',fontproperties=myfont) ax.set_ylabel(u'花萼宽度',fontproperties=myfont) ax.set_title(u'花瓣长度线图',fontproperties=myfont) plt.tight_layout() plt.show()