Annotating time-series data

Introduction to Data Visualization with Matplotlib

Ariel Rokem

Data Scientist

Time-series data

Introduction to Data Visualization with Matplotlib

Annotation

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()

Introduction to Data Visualization with Matplotlib

Positioning the text

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

Introduction to Data Visualization with Matplotlib

Adding arrows to annotation

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

Introduction to Data Visualization with Matplotlib

Customizing arrow properties

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

Introduction to Data Visualization with Matplotlib

Customizing annotations

Introduction to Data Visualization with Matplotlib

Practice annotating plots!

Introduction to Data Visualization with Matplotlib

Preparing Video For Download...