我爱编程

matplotlib画折线图

2018-04-24  本文已影响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()

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

上一篇下一篇

猜你喜欢

热点阅读