Make Beautiful (and Useful) Spaghetti Plots with Python | by Lee Vaughan | Aug, 2023

Stacked line charts are so hot right now!

Photo by Hunter Harritt on Unsplash

There have been a lot of climate change articles recently, and many feature distinctive stacked line charts that summarize data over many decades. Here’s an example from the Climate Reanalyzer that shows how sea temperatures over the last year-and-a-half have been well above average [1]:

Global (60S-60N) Sea Surface Temperature (1981–2023) [1]

And here’s a similar chart from Dr. Zachary Labe’s site showing the extent of Antarctic Sea ice over the last 40+ years [2]:

Antarctic sea ice extent (1978–2023) [2]

These charts have become a popular choice for infographics, such as in this article, but this popularity is a bit surprising [3]. Due to the difficulty in following individual lines through these dense, tangled displays, they’re generally shunned and disparaged as “spaghetti” plots.

But there’s a secret to using spaghetti plots successfully. You must emphasize one or two lines against a diminished background of all the other lines. This strategy lets you place the selected lines within an overall context. Do they represent normal outcomes or are they outliers? Are the results really good or really bad? By superimposing them on a background trend, the story can write itself.

In this Quick Success Data Science project, we’re going to produce a facsimile of the previous Antarctic Sea Ice chart with the Plotly Express graphing library. With this code example, you should be able to generate similar plots for your own datasets.

For data we’ll use a comprehensive public dataset compiled by the National Snow and Ice Data Center, a part of the Cooperative Institute for Research in Environmental Sciences (CIRES) at the University of Colorado, Boulder [4]. This dataset utilizes satellite imagery to track and monitor changes in polar sea ice, such as the “halo” of ice around Antarctica.

Source link

Leave a Comment