This week we’re exploring extreme weather attribution studies. The dataset comes from Carbon Brief’s article Mapped: How climate change affects extreme weather around the world
TidyTuesday
Data Visualization
Python
2025
Author
Peter Gray
Published
August 5, 2025
::: #### 1. Python code
Show code
import pandas as pdimport numpy as npimport seaborn as snsimport matplotlib.pyplot as pltimport foliumimport base64from io import BytesIOattribution_studies = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-08-12/attribution_studies.csv')attribution_studies_raw = pd.read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/main/data/2025/2025-08-12/attribution_studies_raw.csv')classification_colors = {"More severe or more likely to occur": "#e41a1c","Decrease, less severe or less likely to occur": "#377eb8","No discernible human influence": "#4daf4a",}df = attribution_studies_raw[attribution_studies_raw["iso_country_code"].notnull()]df = df[df["classification"] !="Insufficient data/inconclusive"]df = df[df["cb_region"].str.contains("Heisphere")==False]df["classification"]df = df.explode("iso_country_code")df["iso_country_code"] = df["iso_country_code"].str.strip()counts = df.groupby(['cb_region', 'classification']).size().reset_index(name='count')pivot_counts = counts.pivot(index='cb_region', columns='classification', values='count').fillna(0)pivot_percent = pivot_counts.div(pivot_counts.sum(axis=1), axis=0) *100ax = pivot_percent.plot( kind='bar', stacked=True, figsize=(8, 5), color=[classification_colors.get(col, "#cccccc") for col in pivot_percent.columns])for container in ax.containers: labels = [f"{v.get_height():.1f}%"if v.get_height() >0else""for v in container] ax.bar_label(container, labels=labels, label_type='center', fontsize=8, color="white")plt.ylabel('Percentage')plt.xlabel("Region")plt.title('Percentage by Region and Classification')plt.legend( title='Classification', loc='lower right', bbox_to_anchor=(1.5, -1))plt.show()