Sử dụng Pandas, chúng ta sẽ tạo dataframe và đặt đường thẳng đứng trên axes đã tạo, dùng axvline.
Các bước
Dùng pandas tạo data frame.
Tạo data frame giúp tạo trợ giúp.
Dùng axvline(), thêm đường thẳng đứng dọc axes, màu xanh, linestyle="dashed".
Dùng axvline(), thêm đường thẳng đứng dọc axes, màu đỏ, linestyle="dashed".
Hiển thị plot bằng plt.show().
Ví dụ
import pandas as pd
from matplotlib import pyplot as plt
df = pd.DataFrame(index=pd.date_range("2019-07-01", "2019-07-31"))
df["y"] = 1
ax = df.plot()
ax.axvline("2019-07-24", color="green", linestyle="dashed")
ax.axvline("2019-07-31", color="red", linestyle="dashed")
plt.show()
Kết quả
