Created
October 29, 2019 17:57
-
-
Save rabernat/175546e31b9130272fca4e122d436940 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from matplotlib import pyplot as plt | |
import numpy as np | |
%matplotlib inline | |
url = 'https://storage.googleapis.com/pangeo-cmip6/pangeo-cmip6-zarr-consolidated-stores.csv' | |
df = pd.read_csv(url) | |
run_count = df[df.activity_id == 'CMIP'].groupby(['experiment_id', 'source_id']).zstore.count() | |
rcu = run_count.unstack(level=-1) | |
data = rcu.values | |
models = list(rcu.columns) | |
scenarios = list(rcu.index) | |
# adopted from https://matplotlib.org/3.1.1/gallery/images_contours_and_fields/image_annotated_heatmap.html | |
fig, ax = plt.subplots(figsize=(20, 7)) | |
im = ax.imshow(data, cmap='Reds') | |
# We want to show all ticks... | |
ax.set_xticks(np.arange(len(models))) | |
ax.set_yticks(np.arange(len(scenarios))) | |
# ... and label them with the respective list entries | |
ax.set_xticklabels(models) | |
ax.set_yticklabels(scenarios) | |
ax.set_ylim([-0.5, len(scenarios)-0.5]) | |
# Rotate the tick labels and set their alignment. | |
plt.setp(ax.get_xticklabels(), rotation=45, ha="right", | |
rotation_mode="anchor") | |
# Loop over data dimensions and create text annotations. | |
for i in range(len(scenarios)): | |
for j in range(len(models)): | |
if data[i, j] > 0: | |
text = ax.text(j, i, int(data[i, j]), | |
ha="center", va="center", color='c') | |
plt.title('Pangeo CMIP6 Data Holdings') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As of today: