From 8b63fb3f17257e2f83702f6770684d63f82383cc Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 21 May 2022 15:06:42 +0200 Subject: [PATCH] Replace step with stairs and correct subplot_adjusts --- cheatsheets.tex | 15 +++++++-------- scripts/adjustements.py | 16 +++++++++------- scripts/advanced-plots.py | 12 ++++++------ 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/cheatsheets.tex b/cheatsheets.tex index d74754a..15140e7 100644 --- a/cheatsheets.tex +++ b/cheatsheets.tex @@ -432,14 +432,13 @@ \vspace{\fill} % --- Advanced plots -------------------------------------------------------- \begin{myboxed}{Advanced plots} - \plot{advanced-step.pdf}{\textbf{step}(X,Y,[fmt],…)} - {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.step.html} - {\mandatory{X}, - \mandatory{Y}, - \optional{fmt}, - \optional{color}, - \optional{marker}, - \optional{where} } + \plot{advanced-stairs.pdf}{\textbf{stairs}(Y,[edges],…)} + {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.stairs.html} + {\mandatory{Y}, + \optional{edges}, + \optional{orientation}, + \optional{baseline}, + \optional{fill} } {} \plot{advanced-boxplot.pdf}{\textbf{boxplot}(X,…)} {https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.boxplot.html} diff --git a/scripts/adjustements.py b/scripts/adjustements.py index 807474f..b27ae51 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -91,12 +91,13 @@ def int_arrow(p0, p1): ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) ) ax.text(x-4.5, y, "wspace", ha="right", va="center", size="x-small", zorder=20) -x += 45 -ext_arrow( (x-4, y), (x, y), (x+5, y), (x+9, y) ) -ax.text(x-4.5, y, "right", ha="right", va="center", size="x-small", zorder=20) +y=20 +int_arrow( (0, y), (95, y)) +ax.text(80, y, "right", backgroundcolor="white", ha="right", va="center", + size="x-small", zorder=30) y = 0 -x = 25 +x = 22.5 ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) ) ax.text(x, y+9.5, "bottom", ha="center", va="bottom", size="x-small", zorder=20) @@ -104,9 +105,10 @@ def int_arrow(p0, p1): ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) ) ax.text(x, y-4.5, "hspace", ha="center", va="top", size="x-small", zorder=20) -y += 35 -ext_arrow( (x, y-4), (x, y), (x, y+5), (x, y+9) ) -ax.text(x, y-4.5, "top", ha="center", va="top", size="x-small", zorder=20) +x = 31 +int_arrow( (x, 0), (x, 70)) +ax.text(x, 55, "top", backgroundcolor="white", rotation="vertical", + ha="center", va="center", size="x-small", zorder=30) int_arrow((0, -5), (100, -5)) ax.text(50, -5, "figure width", backgroundcolor="white", zorder=30, diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 025378a..94c7477 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -3,7 +3,7 @@ # Released under the BSD License # ----------------------------------------------------------------------------- -# Scripts to generate all the basic plots +# Scripts to generate all the advanced plots import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt @@ -15,15 +15,15 @@ d = 0.01 ax = fig.add_axes([d, d, 1-2*d, 1-2*d]) -# Step plot +# Stairs plot # ----------------------------------------------------------------------------- X = np.linspace(0, 10, 16) -Y = 4 + 2*np.sin(2*X) -ax.step(X, Y, color="C1", linewidth=0.75) +Y = 2*np.sin(2*X+0.3) +ax.stairs(Y, color="C1", linewidth=0.75) ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) -ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) +ax.set_ylim(-4, 4), ax.set_yticks(np.arange(-4, 4)) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-step.pdf") +plt.savefig("../figures/advanced-stairs.pdf") ax.clear() # Violin plot