時系列プロットのカスタマイズ

Pythonで学ぶ時系列データの可視化

Thomas Vincent

Head of Data Science, Getty Images

時系列データのスライシング

discoveries['1960':'1970']
discoveries['1950-01':'1950-12']
discoveries['1960-01-01':'1960-01-15']
Pythonで学ぶ時系列データの可視化

時系列データのサブセットをプロットする

import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
df_subset = discoveries['1960':'1970']
ax = df_subset.plot(color='blue', fontsize=14)
plt.show()

時系列サブセットの例

Pythonで学ぶ時系列データの可視化

マーカーの追加

ax.axvline(x='1969-01-01', 
           color='red', 
           linestyle='--')
ax.axhline(y=100, 
           color='green', 
           linestyle='--')
Pythonで学ぶ時系列データの可視化

マーカーの使用:完全なコード

ax = discoveries.plot(color='blue')
ax.set_xlabel('Date')
ax.set_ylabel('Number of great discoveries')

ax.axvline('1969-01-01', color='red', linestyle='--') ax.axhline(4, color='green', linestyle='--')

プロットへのマーカーの追加

Pythonで学ぶ時系列データの可視化

関心領域のハイライト

ax.axvspan('1964-01-01', '1968-01-01', 
           color='red', alpha=0.5)
ax.axhspan(8, 6, color='green',
           alpha=0.2)
Pythonで学ぶ時系列データの可視化

関心領域のハイライト:完全なコード

ax = discoveries.plot(color='blue')
ax.set_xlabel('Date')
ax.set_ylabel('Number of great discoveries')
ax.axvspan('1964-01-01', '1968-01-01', color='red',
alpha=0.3)
ax.axhspan(8, 6, color='green', alpha=0.3)

プロットへの関心領域の追加

Pythonで学ぶ時系列データの可視化

練習しましょう!

Pythonで学ぶ時系列データの可視化

Preparing Video For Download...