标注时间序列数据

Matplotlib 数据可视化入门

Ariel Rokem

Data Scientist

时间序列数据

Matplotlib 数据可视化入门

标注

fig, ax = plt.subplots()
plot_timeseries(ax, climate_change.index, climate_change['co2'],
               'blue', 'Time', 'CO2 (ppm)')
ax2 = ax.twinx()
plot_timeseries(ax2, climate_change.index, 
                climate_change['relative_temp'],
               'red', 'Time', 'Relative temperature (Celsius)')

ax2.annotate(">1 degree", xy=(pd.Timestamp("2015-10-06"), 1))
plt.show()

Matplotlib 数据可视化入门

定位文本

ax2.annotate(">1 degree",
             xy=(pd.Timestamp('2015-10-06'), 1),
             xytext=(pd.Timestamp('2008-10-06'), -0.2))

Matplotlib 数据可视化入门

为标注添加箭头

ax2.annotate(">1 degree",
             xy=(pd.Timestamp('2015-10-06'), 1),
             xytext=(pd.Timestamp('2008-10-06'), -0.2),
             arrowprops={})

Matplotlib 数据可视化入门

自定义箭头样式

ax2.annotate(">1 degree",
             xy=(pd.Timestamp('2015-10-06'), 1),
             xytext=(pd.Timestamp('2008-10-06'), -0.2),
             arrowprops={"arrowstyle":"->", "color":"gray"})

Matplotlib 数据可视化入门

自定义标注

Matplotlib 数据可视化入门

练习为图表添加标注!

Matplotlib 数据可视化入门

Preparing Video For Download...