Created
January 12, 2024 09:47
-
-
Save thomascamminady/4b260b767f21797bb79d121d2b21b3e9 to your computer and use it in GitHub Desktop.
ftify
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 numpy as np | |
import matplotlib.pyplot as plt | |
from cycler import cycler | |
import matplotlib.patheffects as path_effects | |
# %% | |
np.random.seed(1) | |
n, m = 200, 6 | |
x = np.arange(n) | |
y = np.cumsum(np.random.randn(m, n) * 0.1, axis=1) | |
# %% | |
ft_background = "#FFF1E5" | |
ft_democratblue = "#0F56B5" | |
ft_republicanred = "#EF4647" | |
ft_pink = "#E95D8C" | |
ft_darkred = "#7D062E" | |
ft_darkblue = "#065296" | |
ft_blue = "#2591CE" | |
ft_lightblue = "#72D9E7" | |
ft_greenish = "#A2BC5D" | |
ft_maybegrey = "#716962" | |
ft_golden = "#B89E17" | |
# %% | |
smallfont = 26 | |
largefont = 32 | |
linewidth = 5 | |
plt.rcParams["figure.facecolor"] = ft_background | |
plt.rcParams["axes.facecolor"] = ft_background | |
plt.rcParams["text.color"] = ft_maybegrey | |
plt.rcParams["xtick.color"] = ft_maybegrey | |
plt.rcParams["ytick.color"] = ft_maybegrey | |
plt.rcParams["axes.labelcolor"] = ft_maybegrey | |
plt.rcParams["axes.grid.axis"] = "y" | |
plt.rcParams["axes.grid"] = True | |
plt.rcParams["axes.spines.left"] = False | |
plt.rcParams["axes.spines.right"] = False | |
plt.rcParams["axes.spines.top"] = False | |
plt.rcParams["axes.spines.bottom"] = True | |
plt.rcParams["figure.figsize"] = (20, 12) | |
plt.rcParams["axes.titlesize"] = largefont | |
plt.rcParams["font.size"] = smallfont | |
plt.rcParams["xtick.labelsize"] = smallfont | |
plt.rcParams["ytick.labelsize"] = smallfont | |
plt.rcParams["axes.labelsize"] = smallfont | |
plt.rcParams["ytick.labelsize"] = smallfont | |
plt.rcParams["xtick.major.size"] = 10 | |
plt.rcParams["xtick.major.pad"] = 10 | |
plt.rcParams["ytick.major.size"] = 0 | |
plt.rcParams["ytick.major.pad"] = 10 | |
plt.rcParams["lines.linewidth"] = linewidth | |
plt.rc( | |
"axes", | |
prop_cycle=( | |
cycler( | |
"color", | |
[ft_darkblue, ft_blue, ft_lightblue, ft_pink, ft_darkred, ft_greenish], | |
) | |
), | |
) | |
# %% | |
fig, ax = plt.subplots(constrained_layout=True) | |
for i in range(m): | |
ax.plot(x, y[i, :], lw=linewidth + 1, c="w") # White outline of line | |
p = ax.plot(x, y[i, :]) | |
color = p[-1].get_color() # Match text color with line color | |
text = ax.text( | |
x[-1] + 1, | |
y[i, -1] * 1.05, | |
f" Category {i+1}", | |
fontsize=smallfont, | |
va="center", | |
color=color, | |
) | |
text.set_path_effects( | |
[path_effects.Stroke(linewidth=1, foreground="white"), path_effects.Normal()] | |
) # White outline of text | |
ax.set_ylim(-3, 3) | |
left = -0.06 | |
ax.text( | |
left, | |
1.18, | |
"The main title", | |
ha="left", | |
va="center", | |
transform=ax.transAxes, | |
fontsize=largefont, | |
color="k", | |
) | |
ax.text( | |
left, | |
1.1, | |
"And this is a smaller title", | |
ha="left", | |
va="center", | |
transform=ax.transAxes, | |
) | |
ax.text( | |
left, -0.15, "Here is a footnote.", ha="left", va="center", transform=ax.transAxes | |
) | |
ax.set_xlabel("This is the x-label") | |
ax.set_ylabel("This is the y-label") | |
plt.savefig("sampleplot.png", dpi=100) | |
# %% |
Author
thomascamminady
commented
Jan 12, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment