python绘图-用scatter绘制散点图

import matplotlib.pyplot as plt

if __name__ == '__main__':
    #设置使能够显示中文
    plt.rcParams['font.sans-serif'] = [u'SimHei']
    plt.rcParams['axes.unicode_minus'] = False
    #设置图片大小
    plt.figure(figsize=(20, 8), dpi=80)
    x_3 = range(1, 32)
    x_10 = range(51, 82)
    y_3 = [13, 15, 17, 13, 15, 14, 18, 19, 20, 19, 21, 22, 20, 19, 23, 24, 25, 23, 21, 25, 24, 26, 25, 26, 27, 23, 26,
           25, 25, 26, 24]
    y_10 = [33, 35, 37, 33, 35, 34, 32, 33, 30, 31, 31, 32, 30, 31, 33, 34, 35, 33, 31, 35, 34, 32, 25, 26, 27, 23, 22,
            21, 20, 22, 21]

    plt.scatter(x_3, y_3,label='3月')
    plt.scatter(x_10, y_10,label='10月')
    #调整刻度
    _x=list(x_3)+list(x_10)
    _xtick_labels=['3月{}号'.format(i) for i in x_3]
    _xtick_labels+=['10月{}号'.format(i-50) for i in x_10]
    plt.xticks(_x,_xtick_labels,rotation=45)
    plt.xlabel('时间')
    plt.ylabel('气温')
    plt.title('3月和10月气温分布图')
    plt.legend()
    plt.show()

python绘图-用scatter绘制散点图_第1张图片

你可能感兴趣的:(python绘图知识,python,机器学习,开发语言)