美文网首页我爱编程
matplotlib画折线图

matplotlib画折线图

作者: 德先森的书 | 来源:发表于2018-04-24 22:55 被阅读0次

    1读取数据
    import pandas as pd
    unrate = pd.read_csv('unrate.csv')
    unrate['DATE'] = pd.to_datetime(unrate['DATE']) #转换date数据格式
    print(unrate.head(12))
    2 画背景
    import matplotlib.pyplot as plt
    plt.plot()
    plt.show()
    3 画折线图
    first_twelve = unrate[0:12]
    plt.plot(first_twelve['DATE'], first_twelve['VALUE'])
    plt.show()
    4 图表调整

    xlabel(): accepts a string value, which gets set as the x-axis label.

    ylabel(): accepts a string value, which is set as the y-axis label.

    title(): accepts a string value, which is set as the plot title.

    plt.plot(first_twelve['DATE'], first_twelve['VALUE'])
    plt.xticks(rotation=45)
    plt.xlabel('Month')
    plt.ylabel('Unemployment Rate')
    plt.title('Monthly Unemployment Trends, 1948')
    plt.show()

    数据和代码参考唐宇迪老师的机器学习课程

    相关文章

      网友评论

        本文标题:matplotlib画折线图

        本文链接:https://www.haomeiwen.com/subject/kqyslftx.html