1. # coding=utf-8
    2. from matplotlib import pyplot as plt
    3. from matplotlib import font_manager
    4. my_font = font_manager.FontProperties(fname="/System/Library/Fonts/PingFang.ttc")
    5. y_1 = [1,0,1,1,2,4,3,2,3,4,4,5,6,5,4,3,3,1,1,1]
    6. y_2 = [1,0,3,1,2,2,3,3,2,1 ,2,1,1,1,1,1,1,1,1,1]
    7. x = range(11,31)
    8. #设置图形大小
    9. plt.figure(figsize=(20,8),dpi=80)
    10. plt.plot(x,y_1,label="自己",color="#F08080")
    11. plt.plot(x,y_2,label="同桌",color="#DB7093",linestyle="--")
    12. #设置x轴刻度
    13. _xtick_labels = ["{}岁".format(i) for i in x]
    14. plt.xticks(x,_xtick_labels,fontproperties=my_font)
    15. # plt.yticks(range(0,9))
    16. #绘制网格
    17. plt.grid(alpha=0.4,linestyle=':')
    18. #添加图例
    19. plt.legend(prop=my_font,loc="upper left")
    20. #展示
    21. plt.show()