How one can use the complete capabilities of Matplotlib to inform a extra compelling story

GDP Evolution over time of the 5 richest nations — Picture by Creator

A couple of months again I wrote an article about bar charts and the way you would make them clear, self-explanatory, and visually pleasing to the viewers to be able to inform a extra compelling story (hyperlink beneath).

On this article I look into line charts as a substitute, which produce other specificities which are value exploring.

Matplotlib makes it fast and simple to plot knowledge with off-the-shelf features however the high-quality tuning steps take extra effort.

I spent fairly a while researching finest practices to construct compelling charts with Matplotlib, so that you don’t need to.

The concept is to go from this…

… to that:

All photographs, except in any other case famous, are by the writer.

As an example the methodology, I used a public dataset containing nations’ GDP data over the previous 50 years:

Supply: World Financial institution nationwide accounts knowledge, and OECD Nationwide Accounts knowledge recordsdata.
License URL:
License Kind: CC BY-4.0

After importing the mandatory packages to learn the information and construct our graphs, I merely filtered on the High 20 nations of 2022:

import pandas as pd
import matplotlib.pyplot as plt
from datetime import timedelta

# Learn the information
df = pd.read_csv('88a1e584-0a94-4e73-b650-749332831ef4_Data.csv', sep=',')
df.drop(['Series Name', 'Series Code', 'Country Code']…

Leave a Reply

Your email address will not be published. Required fields are marked *