import pandas as pd
unrate = pd.read_csv('unrate.csv')
unrate['DATE'] = pd.to_datetime(unrate['DATE'])#类型转换
print(unrate.head(12))
DATE VALUE 0 1948-01-01 3.4 1 1948-02-01 3.8 2 1948-03-01 4.0 3 1948-04-01 3.9 4 1948-05-01 3.5 5 1948-06-01 3.6 6 1948-07-01 3.6 7 1948-08-01 3.9 8 1948-09-01 3.8 9 1948-10-01 3.7 10 1948-11-01 3.8 11 1948-12-01 4.0
import matplotlib.pyplot as plt
#%matplotlib inline
#Using the different pyplot functions, we can create, customize, and display a plot. For example, we can use 2 functions to :
plt.plot()
plt.show()
first_twelve = unrate[0:12]
plt.plot(first_twelve['DATE'], first_twelve['VALUE'])#左边当x轴,右边y轴
plt.show()
plt.plot(first_twelve['DATE'], first_twelve['VALUE'])
plt.xticks(rotation=45)#指定角度45°
#print help(plt.xticks)
plt.show()
plt.plot(first_twelve['DATE'], first_twelve['VALUE'])
plt.xticks(rotation=90)
plt.xlabel('Month')
plt.ylabel('Unemployment Rate')
plt.title('Monthly Unemployment Trends, 1948')
plt.show()
unrate.csv
DATE | VALUE |
1948/1/1 | 3.4 |
1948/2/1 | 3.8 |
1948/3/1 | 4 |
1948/4/1 | 3.9 |
1948/5/1 | 3.5 |
1948/6/1 | 3.6 |
1948/7/1 | 3.6 |
1948/8/1 | 3.9 |
1948/9/1 | 3.8 |
1948/10/1 | 3.7 |
1948/11/1 | 3.8 |
1948/12/1 | 4 |
1949/1/1 | 4.3 |
1949/2/1 | 4.7 |
1949/3/1 | 5 |
1949/4/1 | 5.3 |
1949/5/1 | 6.1 |
1949/6/1 | 6.2 |
1949/7/1 | 6.7 |
1949/8/1 | 6.8 |
1949/9/1 | 6.6 |
1949/10/1 | 7.9 |
1949/11/1 | 6.4 |
1949/12/1 | 6.6 |
1950/1/1 | 6.5 |
1950/2/1 | 6.4 |
1950/3/1 | 6.3 |
1950/4/1 | 5.8 |
1950/5/1 | 5.5 |
1950/6/1 | 5.4 |
1950/7/1 | 5 |
1950/8/1 | 4.5 |
1950/9/1 | 4.4 |
1950/10/1 | 4.2 |
1950/11/1 | 4.2 |
1950/12/1 | 4.3 |
1951/1/1 | 3.7 |
1951/2/1 | 3.4 |
1951/3/1 | 3.4 |
1951/4/1 | 3.1 |
1951/5/1 | 3 |
1951/6/1 | 3.2 |
1951/7/1 | 3.1 |
1951/8/1 | 3.1 |
1951/9/1 | 3.3 |
1951/10/1 | 3.5 |
1951/11/1 | 3.5 |
1951/12/1 | 3.1 |