1. Beyond summary statistics
We will now go beyond summary statistics and work on producing meaningful visualizations from the jobs dataset.
2. Facet plots of the jobs dataset
In chapter 4, we emphasized techniques to facilitate the simultaneous visualization of multiple time series. Specifically, we leveraged the subplots and layout arguments available in the dot plot() method to create faceted plots. The total number of subplots 4x4 is specified based on the number of time series in the jobs dataset. We will use a figure size of (20, 16), which provides a large enough area to clearly visualize the time series data in the jobs DataFrame.
3. Facet plots of the jobs dataset
This is an extremely interesting plot. As you can see, the unemployment rate in the USA skyrocketed after the 2008 financial crisis. It is impressive to see how all industries were affected!
4. Annotating events in the jobs dataset
Since 2008 appears to be the year when unemployment rate in the USA started increasing, let's annotate our plot with verticals lines using the familiar axvline notation. The first line plots all the time series in the jobs dataset onto one graph. Note that we override the default matplotlib color scheme by specifying the Dark2 colormap. Finally, line 2 and 3 annotate the graph with black vertical lines at January 2008 and January 2009.
5. Annotating events in the jobs dataset
These lines clearly highlight the areas of interest in our data.
6. Taking seasonal average in the jobs dataset
Like we saw in Chapter 2, in situations where datasets such as the jobs DataFrame contain an index of the datetime type, it is possible to directly extract the day, month or year of each dates in the index. The first line of this code prints out the index of the jobs DataFrame and confirms that it is of the datetime type. The second line extracts the month of each date in the index of the jobs DataFrame and then computes the monthly averages using the dot groupby() and dot mean() methods.
7. Monthly averages in the jobs dataset
Let's now plot the monthly averages of unemployment rates for the different industries in the jobs dataset. Notice how once again we are using the Dark2 color scheme. The second line specifies where the legend should be placed. As you can see, the legend has been moved outside the main plot using the ax-dot-legend() method. Use the bbox_to_anchor argument to place the legend box at a desired location, and then use the loc argument to align the legend in the center left of this box.
8. Monthly averages in the jobs dataset
The resulting plot shows some interesting patterns! For example, the unemployment rate for the Agriculture and Construction industries shows significant peaks during the winter months, which is consistent with the idea that these industries will far less active during the cold weather months!
9. Time to practice!
Time to practice!