Tùy chỉnh biểu đồ chuỗi thời gian của bạn

Trực quan hóa dữ liệu chuỗi thời gian trong Python

Thomas Vincent

Head of Data Science, Getty Images

Cắt lát dữ liệu chuỗi thời gian

discoveries['1960':'1970']
discoveries['1950-01':'1950-12']
discoveries['1960-01-01':'1960-01-15']
Trực quan hóa dữ liệu chuỗi thời gian trong Python

Vẽ tập con dữ liệu chuỗi thời gian

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

Ví dụ về tập con chuỗi thời gian

Trực quan hóa dữ liệu chuỗi thời gian trong Python

Thêm mốc đánh dấu

ax.axvline(x='1969-01-01', 
           color='red', 
           linestyle='--')
ax.axhline(y=100, 
           color='green', 
           linestyle='--')
Trực quan hóa dữ liệu chuỗi thời gian trong Python

Dùng mốc đánh dấu: mã đầy đủ

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='--')

Thêm mốc vào biểu đồ

Trực quan hóa dữ liệu chuỗi thời gian trong Python

Làm nổi bật vùng quan tâm

ax.axvspan('1964-01-01', '1968-01-01', 
           color='red', alpha=0.5)
ax.axhspan(8, 6, color='green',
           alpha=0.2)
Trực quan hóa dữ liệu chuỗi thời gian trong Python

Làm nổi bật vùng quan tâm: mã đầy đủ

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)

Thêm vùng quan tâm vào biểu đồ

Trực quan hóa dữ liệu chuỗi thời gian trong Python

Cùng luyện tập nào!

Trực quan hóa dữ liệu chuỗi thời gian trong Python

Preparing Video For Download...