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/Hiragino Sans GB.ttc")
    5. y_3 = [11,17,16,11,12,11,12,6,6,7,8,9,12,15,14,17,18,21,16,17,20,14,15,15,15,19,21,22,22,22,23]
    6. y_10 = [26,26,28,19,21,17,16,19,18,20,20,19,22,23,17,20,21,20,22,15,11,15,5,13,17,10,11,13,12,13,6]
    7. x_3 = range(1,32)
    8. x_10 = range(51,82)
    9. #设置图形大小
    10. plt.figure(figsize=(20,8),dpi=80)
    11. #使用scatter方法绘制散点图,和之前绘制折线图的唯一区别
    12. plt.scatter(x_3,y_3,label="3月份")
    13. plt.scatter(x_10,y_10,label="10月份")
    14. #调整x轴的刻度
    15. _x = list(x_3)+list(x_10)
    16. _xtick_labels = ["3月{}日".format(i) for i in x_3]
    17. _xtick_labels += ["10月{}日".format(i-50) for i in x_10]
    18. plt.xticks(_x[::3],_xtick_labels[::3],fontproperties=my_font,rotation=45)
    19. #添加图例
    20. plt.legend(loc="upper left",prop=my_font)
    21. #添加描述信息
    22. plt.xlabel("时间",fontproperties=my_font)
    23. plt.ylabel("温度",fontproperties=my_font)
    24. plt.title("标题",fontproperties=my_font)
    25. #展示
    26. plt.show()