在图上显示数据
折线图
from matplotlib import pyplot
from matplotlib import font_manager
my_font=font_manager.FontProperties(fname="C:\Windows\Fonts\simhei.ttf")#引用中文字体,该字体为本地字体,word字体一般在此路径
a = range(11, 31)
y = [1, 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1, ]
y2 = [ 0, 1, 1, 2, 4, 3, 2, 3, 4, 4, 5, 6, 5, 4, 3, 3, 1, 1, 1, 1]
pyplot.figure(figsize=(15, 15), dpi=100) # 图形设置
pyplot.plot(a, y,linestyle=":") # 绘制折线图,要想增加图例还需要引用pyplot.legend()函数,linestyle表示虚线实线等风格
pyplot.plot(a, y2,linestyle="--") #绘制第二个折线图,":"表示点虚线
#引用pyplot.legend()函数中的labels来增加图例,只有此处用汉字使用prop,其他都用properties,loc表示位置,具体可参考legend文档
_a = ["{}years".format(i) for i in a] # 用_a代替a,这样可以不仅显示数字,还能显示字符串
pyplot