Visualization For Science

Share this post
NASA Climate Spiral
viz4sci.substack.com

NASA Climate Spiral

Mar 30
2
Share this post
NASA Climate Spiral
viz4sci.substack.com

Welcome to the latest issue of the V4Sci substack. This week we create our own version of the climate spiral animation that NASA published recently: https://climate.nasa.gov/climate_resources/300/video-climate-spiral/. We use the original dataset and add a few modifications of our own!

As usual, we use just matplotlib and make all the code public in the form of a self contained Jupyter notebook.

Share

We’re looking forward to hearing your thoughts, so go ahead and….

Leave a comment

NASA has recently published a nice animation of the monthly global temperature anomaly (changes from an average) between the years 1880 and 2022. Colder than average temperatures are represented in blue and white, while warmer than average temperatures are shown in red. Unsurprisingly, global temperatures have increased from mainly human activities as time has progressed.

We download the original dataset form here and perform a small amount of preprocessing

to put it in an easily useable form with one value per (time ordered) row.

With this format, it’s relatively easy to generate a quick and dirty plot using matplotlib polar plotting and color mapping capabilities. The only tricky part is to remember that we must use a LineCollection so that we may change the color of each individual line segment (corresponding to each month):

The end result is not too shabby for a first try:

but we still have some ways to go before we get close to the original.

As the original figure doesn’t include a color legend as recommended, we add our first modification and include a color bar by adding a few extra lines of code:

Much better!

Finally, we modify the color palette so that we may have a black background and white text throughout:

The full code to generate this figure is simply:

where we had to add a few extra lines to change the font colors.

The final step is to animate this figure. As we saw in previous posts, matplotlib makes it easy to programmatically generate animations by simply supplying a function to update the original plot for each new frame. The only thing we must keep in mind is that it is best to generate an empty figure and then simply update the data for each new frame. We can do this by using the set_array and set_text methods of LineCollection and text objects, respectively.

The final code of the animation is fairly straightforward and mostly just a reshuffling of the code of the static figure:

In order to generate a smaller file, we use the ffmpeg writer to generate an mp4 file that we can easily upload to Youtube. The final result is then:

Finally, you can find the full jupyter notebook in the form of a gist:

Thank you for making it through another post of the Visualization for Science series and your continued support. We would love to hear your thoughts, so please:

Leave a comment

And don’t forget to

Share

to help us grow and:

to help support our future posts and gain access to the full archive.

Share this post
NASA Climate Spiral
viz4sci.substack.com
Comments

Create your profile

0 subscriptions will be displayed on your profile (edit)

Skip for now

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.

TopNew

No posts

Ready for more?

© 2022 Data For Science
Privacy ∙ Terms ∙ Collection notice
Publish on Substack Get the app
Substack is the home for great writing