Created
January 10, 2025 18:56
-
-
Save RemDelaporteMathurin/64e31eb9194cc6e26bbf4964f0c06380 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 matplotlib.pyplot as plt | |
import squarify | |
import pandas as pd | |
from pypalettes import load_cmap | |
from highlight_text import fig_text | |
dark_mode = True | |
cmap = load_cmap("Acadia") | |
# data from https://doi.org/10.1016/j.fusengdes.2018.04.090 | |
df = pd.DataFrame( | |
{ | |
"rate": [2.5, 34, 50], | |
"label": [ | |
"Average tritium production (1 year)", | |
"Available tritium reserves (2018)", | |
"Consuption of a 1 GWth \n fusion reactor (1 year)", | |
], | |
} | |
) | |
labels = [f"{name} \n{value} kg" for name, value in zip(df["label"], df["rate"])] | |
colours = [cmap(i + 2) for i, _ in enumerate(df["rate"])] | |
plt.figure(figsize=(10, 8)) | |
squarify.plot( | |
sizes=df["rate"], | |
label=labels, | |
pad=True, | |
color=colours, | |
text_kwargs={"color": "white", "fontsize": 9, "fontweight": "bold"}, | |
) | |
plt.axis("off") | |
if dark_mode: | |
title_color = "white" | |
text_color = "white" | |
else: | |
title_color = "black" | |
text_color = "gray" | |
text = """<The tritium issue> | |
<Data source: Pearson et al, Fusion Engineering and Design 136 (2018) 1140–1148> | |
""" | |
fig_text( | |
x=0.133, | |
y=0.98, | |
s=text, | |
color="black", | |
highlight_textprops=[ | |
{"fontsize": 20, "fontweight": "bold", "color": title_color}, | |
{"fontsize": 9, "color": text_color}, | |
], | |
fontsize=14, | |
ha="left", | |
) | |
plt.savefig("tritium_consumption.svg", bbox_inches="tight", transparent=True) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment