Annotate significant events in time series data

When plotting the Finance, Information, Manufacturing and Construction time series of the jobs DataFrame, you observed a distinct increase in unemployment rates during 2001 and 2008. In general, time series plots can be made even more informative if you include additional annotations that emphasize specific observations or events. This allows you to quickly highlight parts of the graph to viewers, and can help infer what may have caused a specific event.

Recall that you have already set the datestamp column as the index of the jobs DataFrame, so you are prepared to directly annotate your plots with vertical or horizontal lines.

This exercise is part of the course

Visualizing Time Series Data in Python

View Course

Exercise instructions

_ Plot all the time series in jobs on a single graph, and use the Spectral color palette.

  • Add a blue vertical line at the date 2001-07-01.
  • Add a second blue vertical line at the date 2008-09-01.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Plot all time series in the jobs DataFrame
ax = ____(____, fontsize=6, linewidth=0.8)

# Set labels and legend
ax.set_xlabel('Date', fontsize=10)
ax.set_ylabel('Unemployment Rate', fontsize=10)
ax.set_title('Unemployment rate of U.S. workers by industry', fontsize=10)
ax.legend(loc='center left', bbox_to_anchor=(1.0, 0.5))

# Annotate your plots with vertical lines
____(____, color='blue', linestyle='--', linewidth=0.8)
____(____, color='blue', linestyle='--', linewidth=0.8)

# Show plot
plt.show()