From 7a044072ed7fefff3d6051b3f3988355272aee9e Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 28 Mar 2023 21:39:53 -0400 Subject: [PATCH] Save figures in a path relative to the script This allows running them from the `scripts` directory, _or_ the top of the checkout. --- scripts/adjustements.py | 6 +++++- scripts/advanced-plots.py | 23 ++++++++++++--------- scripts/anatomy.py | 8 +++++++- scripts/annotate.py | 6 +++++- scripts/annotation-arrow-styles.py | 7 ++++++- scripts/annotation-connection-styles.py | 7 ++++++- scripts/basic-plots.py | 27 +++++++++++++++---------- scripts/colorbar.py | 7 ++++++- scripts/colormaps.py | 6 +++++- scripts/colornames.py | 7 +++++-- scripts/colors.py | 7 ++++++- scripts/extents.py | 7 ++++++- scripts/fonts.py | 8 +++++--- scripts/interpolations.py | 7 ++++++- scripts/layouts.py | 19 ++++++++++------- scripts/legend.py | 6 +++++- scripts/linestyles.py | 6 +++++- scripts/markers.py | 6 +++++- scripts/plot-variations.py | 23 ++++++++++++--------- scripts/projections.py | 10 ++++++--- scripts/scales.py | 13 ++++++++---- scripts/sine.py | 17 ++++++++++------ scripts/styles.py | 7 ++++++- scripts/text-alignments.py | 7 ++++++- scripts/tick-formatters.py | 8 ++++++-- scripts/tick-locators.py | 8 ++++++-- scripts/tick-multiple-locator.py | 8 ++++++-- scripts/tip-color-range.py | 7 ++++++- scripts/tip-colorbar.py | 7 ++++++- scripts/tip-dotted.py | 8 +++++++- scripts/tip-dual-axis.py | 9 +++++++-- scripts/tip-font-family.py | 8 ++++++-- scripts/tip-hatched.py | 7 ++++++- scripts/tip-multiline.py | 8 +++++++- scripts/tip-outline.py | 7 ++++++- scripts/tip-post-processing.py | 7 ++++++- scripts/tip-transparency.py | 7 ++++++- 37 files changed, 259 insertions(+), 87 deletions(-) diff --git a/scripts/adjustements.py b/scripts/adjustements.py index 807474f..8b111fa 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -3,12 +3,16 @@ # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt import matplotlib.patches as mpatches from matplotlib.collections import PatchCollection +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(4.25, 4.25 * 95/115)) ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1, xlim=(0-5, 100+10), ylim=(-10, 80+5), xticks=[], yticks=[]) @@ -125,5 +129,5 @@ def int_arrow(p0, p1): rotation="vertical", ha="center", va="center", size="x-small") -plt.savefig("../figures/adjustments.pdf") +fig.savefig(ROOT_DIR / "figures/adjustments.pdf") # plt.show() diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 025378a..9bc44e7 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -4,10 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 mpl.rcParams['xtick.major.size'] = 0.0 @@ -23,7 +28,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/advanced-step.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-step.pdf") ax.clear() # Violin plot @@ -39,7 +44,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-violin.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-violin.pdf") ax.clear() # Boxplot @@ -61,7 +66,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-boxplot.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-boxplot.pdf") ax.clear() # Barbs plot @@ -76,7 +81,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-barbs.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-barbs.pdf") ax.clear() # Event plot @@ -90,7 +95,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-event.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-event.pdf") ax.clear() # Errorbar plot @@ -104,7 +109,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-errorbar.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-errorbar.pdf") ax.clear() # Hexbin plot @@ -119,7 +124,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-hexbin.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-hexbin.pdf") ax.clear() # Hist plot @@ -131,7 +136,7 @@ ax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-hist.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-hist.pdf") ax.clear() # Xcorr plot @@ -145,5 +150,5 @@ ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25, .25, 9)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/advanced-xcorr.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-xcorr.pdf") ax.clear() diff --git a/scripts/anatomy.py b/scripts/anatomy.py index 4a32544..cbe47df 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -3,10 +3,16 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- + +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter + +ROOT_DIR = Path(__file__).parent.parent + np.random.seed(123) X = np.linspace(0.5, 3.5, 100) @@ -136,5 +142,5 @@ def text(x, y, text): connectionstyle="arc3", color=color)) -plt.savefig("../figures/anatomy.pdf") +fig.savefig(ROOT_DIR / "figures/anatomy.pdf") # plt.show() diff --git a/scripts/annotate.py b/scripts/annotate.py index 4254941..4b9d753 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -2,11 +2,15 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(6, 1)) # ax = plt.subplot(111, frameon=False, aspect=.1) # b = 0.0 @@ -23,5 +27,5 @@ plt.text( 5.5, 0.6, "xy\nxycoords", size=10, va="top", ha="center", color=".5") plt.text( .75, 0.6, "xytext\ntextcoords", size=10, va="top", ha="center", color=".5") -plt.savefig("../figures/annotate.pdf") +fig.savefig(ROOT_DIR / "figures/annotate.pdf") # plt.show() diff --git a/scripts/annotation-arrow-styles.py b/scripts/annotation-arrow-styles.py index 648a4c4..f0963cb 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -1,6 +1,11 @@ +from pathlib import Path + import matplotlib.pyplot as plt import matplotlib.patches as mpatches + +ROOT_DIR = Path(__file__).parent.parent + styles = mpatches.ArrowStyle.get_styles() @@ -29,5 +34,5 @@ def demo_con_style(ax, connectionstyle): transform=ax.transAxes, family="Source Code Pro", ha="center", va="top") -plt.savefig("../figures/annotation-arrow-styles.pdf") +fig.savefig(ROOT_DIR / "figures/annotation-arrow-styles.pdf") # plt.show() diff --git a/scripts/annotation-connection-styles.py b/scripts/annotation-connection-styles.py index 64fa300..868aeca 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -1,6 +1,11 @@ +from pathlib import Path + import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + + def demo_con_style(ax, connectionstyle): x1, y1 = 0.3, 0.2 x2, y2 = 0.8, 0.6 @@ -33,5 +38,5 @@ def demo_con_style(ax, connectionstyle): ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1) fig.tight_layout(pad=0.2) -plt.savefig("../figures/annotation-connection-styles.pdf") +fig.savefig(ROOT_DIR / "figures/annotation-connection-styles.pdf") # plt.show() diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index d7a0c35..ec3cdcc 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -4,10 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 mpl.rcParams['xtick.major.size'] = 0.0 @@ -23,7 +28,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/basic-plot.pdf") +fig.savefig(ROOT_DIR / "figures/basic-plot.pdf") ax.clear() # Basic line plot (color)blaPwd @@ -35,7 +40,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/basic-plot-color.pdf") +fig.savefig(ROOT_DIR / "figures/basic-plot-color.pdf") ax.clear() # Basic scatter plot @@ -48,7 +53,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/basic-scatter.pdf") +fig.savefig(ROOT_DIR / "figures/basic-scatter.pdf") ax.clear() # Basic bar plot @@ -62,7 +67,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125) -plt.savefig("../figures/basic-bar.pdf") +fig.savefig(ROOT_DIR / "figures/basic-bar.pdf") ax.clear() # Basic imshow plot @@ -75,7 +80,7 @@ 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.grid(linewidth=0.25, color="white") -plt.savefig("../figures/basic-imshow.pdf") +fig.savefig(ROOT_DIR / "figures/basic-imshow.pdf") ax.clear() # Basic pcolormesh plot @@ -87,7 +92,7 @@ plt.pcolormesh(X, Y, Z, cmap='Oranges', shading='auto') ax.set_xlim(-3, 3), ax.set_xticks(np.arange(-3, 4)) ax.set_ylim(-3, 3), ax.set_yticks(np.arange(-3, 4)) -plt.savefig("../figures/basic-pcolormesh.pdf") +fig.savefig(ROOT_DIR / "figures/basic-pcolormesh.pdf") ax.clear() # Basic contour plot @@ -100,7 +105,7 @@ linewidths=0.125, nchunk=10) ax.set_xlim(0, 8), ax.set_xticks(np.arange(1, 8)) ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) -plt.savefig("../figures/basic-contour.pdf") +fig.savefig(ROOT_DIR / "figures/basic-contour.pdf") ax.clear() # Basic pie plot @@ -117,7 +122,7 @@ wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True) ax.pie(X, colors=colors, radius=3, center=(4, 4), wedgeprops={"linewidth": 0.25, "edgecolor": "white"}, frame=True) -plt.savefig("../figures/basic-pie.pdf") +fig.savefig(ROOT_DIR / "figures/basic-pie.pdf") ax.clear() # Basic text plot @@ -128,7 +133,7 @@ ax.grid(linewidth=0.25, color="0.75") ax.text(4, 4, "TEXT", color="C1", size=8, weight="bold", ha="center", va="center", rotation=25) -plt.savefig("../figures/basic-text.pdf") +fig.savefig(ROOT_DIR / "figures/basic-text.pdf") ax.clear() # Basic fill plot @@ -143,7 +148,7 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125, color="0.75") -plt.savefig("../figures/basic-fill.pdf") +fig.savefig(ROOT_DIR / "figures/basic-fill.pdf") ax.clear() # Basic quiver plot @@ -158,5 +163,5 @@ ax.set_ylim(0, 8), ax.set_yticks(np.arange(1, 8)) ax.set_axisbelow(True) ax.grid(linewidth=0.125, color="0.75") -plt.savefig("../figures/basic-quiver.pdf") +fig.savefig(ROOT_DIR / "figures/basic-quiver.pdf") ax.clear() diff --git a/scripts/colorbar.py b/scripts/colorbar.py index 495cccc..31c326a 100644 --- a/scripts/colorbar.py +++ b/scripts/colorbar.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- + +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(6, .65)) # ax = plt.subplot(111, frameon=False, aspect=.1) b = 0.025 @@ -19,5 +24,5 @@ plt.colorbar(sm, cax=ax, ticks=np.linspace(0, 1, 11), orientation="horizontal") -plt.savefig("../figures/colorbar.pdf") +fig.savefig(ROOT_DIR / "figures/colorbar.pdf") # plt.show() diff --git a/scripts/colormaps.py b/scripts/colormaps.py index a0a0f4b..9e6bca8 100644 --- a/scripts/colormaps.py +++ b/scripts/colormaps.py @@ -1,7 +1,11 @@ +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) @@ -62,5 +66,5 @@ family = "Source Pro Serif", size=10, ha="center", va="center") """ - plt.savefig("../figures/colormap-%s.pdf" % cmap) + fig.savefig(ROOT_DIR / f"figures/colormap-{cmap}.pdf") ax.clear() diff --git a/scripts/colornames.py b/scripts/colornames.py index 0f0260e..5149107 100644 --- a/scripts/colornames.py +++ b/scripts/colornames.py @@ -5,12 +5,15 @@ Simple plot example with the named colors and its visual representation. """ -from __future__ import division + +from pathlib import Path import matplotlib.pyplot as plt from matplotlib import colors as mcolors +ROOT_DIR = Path(__file__).parent.parent + colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS) # Sort colors by hue, saturation, value and name. @@ -53,5 +56,5 @@ top=1, bottom=0, hspace=0, wspace=0) -plt.savefig("../figures/colornames.pdf") +fig.savefig(ROOT_DIR / "figures/colornames.pdf") # plt.show() diff --git a/scripts/colors.py b/scripts/colors.py index 9d323e3..0e6c83c 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- + +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + figsize = 4.0, 0.25 fig = plt.figure(figsize=figsize) ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1) @@ -36,5 +41,5 @@ ax.text((i+0.5)*dx, (ymin+ymax)/2, text, color=color, zorder=10, family="Source Code Pro", size=9, ha="center", va="center") - plt.savefig("../figures/colors-%s.pdf" % name) + fig.savefig(ROOT_DIR / f"figures/colors-{name}.pdf") ax.clear() diff --git a/scripts/extents.py b/scripts/extents.py index 28a0236..2a49b85 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -3,11 +3,16 @@ # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + # Scripts to generate all the basic plots import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + Z = np.arange(5*5).reshape(5, 5) fig = plt.figure(figsize=(8, 5)) @@ -62,5 +67,5 @@ plt.tight_layout() -plt.savefig("../figures/extents.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/extents.pdf", dpi=600) # plt.show() diff --git a/scripts/fonts.py b/scripts/fonts.py index d164ae7..0af92fe 100644 --- a/scripts/fonts.py +++ b/scripts/fonts.py @@ -2,11 +2,13 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- -import pathlib +from pathlib import Path import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(4.25, 3.8)) ax = fig.add_axes([0, 0, 1, 1], frameon=False, xticks=[], yticks=[], xlim=[0, 40], ylim=[0, 38]) @@ -22,7 +24,7 @@ text = "The quick brown fox jumps over the lazy dog" for i, variant in enumerate(variants.keys()): ax.text(1, y, text, size=9, va="center", - font=pathlib.Path(variants[variant]).resolve()) + font=Path(variants[variant]).resolve()) ax.text(39, y, variant, color="0.25", va="center", ha="right", @@ -107,5 +109,5 @@ y += 1.65* max(sizes[size], sizes["small"]) -plt.savefig("../figures/fonts.pdf") +fig.savefig(ROOT_DIR / "figures/fonts.pdf") # plt.show() diff --git a/scripts/interpolations.py b/scripts/interpolations.py index 2a135ef..be998e7 100644 --- a/scripts/interpolations.py +++ b/scripts/interpolations.py @@ -1,6 +1,11 @@ +from pathlib import Path + import matplotlib.pyplot as plt import numpy as np + +ROOT_DIR = Path(__file__).parent.parent + methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos'] @@ -18,5 +23,5 @@ transform=ax.transData, ha="center", va="center") plt.tight_layout() -plt.savefig("../figures/interpolations.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/interpolations.pdf", dpi=600) # plt.show() diff --git a/scripts/layouts.py b/scripts/layouts.py index 9438c5d..1d4f724 100644 --- a/scripts/layouts.py +++ b/scripts/layouts.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(0.4, 0.4)) margin = 0.01 fig.subplots_adjust(left=margin, right=1-margin, top=1-margin, bottom=margin) @@ -18,7 +23,7 @@ for i in range(nrows*ncols): ax = plt.subplot(ncols, nrows, i+1) ax.set_xticks([]), ax.set_yticks([]) -plt.savefig("../figures/layout-subplot.pdf") +fig.savefig(ROOT_DIR / "figures/layout-subplot.pdf") fig.clear() # Subplots (colored) @@ -29,7 +34,7 @@ ax.set_xticks([]), ax.set_yticks([]) if i == 0: ax.set_facecolor("#ddddff") if i == 8: ax.set_facecolor("#ffdddd") -plt.savefig("../figures/layout-subplot-color.pdf") +fig.savefig(ROOT_DIR / "figures/layout-subplot-color.pdf") fig.clear() # Spines @@ -37,7 +42,7 @@ ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[]) ax.spines["top"].set_color("None") ax.spines["right"].set_color("None") -plt.savefig("../figures/layout-spines.pdf") +fig.savefig(ROOT_DIR / "figures/layout-spines.pdf") fig.clear() @@ -49,7 +54,7 @@ ax3 = fig.add_subplot(gs[1:, -1], xticks=[], yticks=[]) ax4 = fig.add_subplot(gs[-1, 0], xticks=[], yticks=[]) ax5 = fig.add_subplot(gs[-1, -2], xticks=[], yticks=[]) -plt.savefig("../figures/layout-gridspec.pdf") +fig.savefig(ROOT_DIR / "figures/layout-gridspec.pdf") fig.clear() # Gridspec (colored) @@ -61,7 +66,7 @@ ax3 = fig.add_subplot(gs[1:, -1], xticks=[], yticks=[]) ax4 = fig.add_subplot(gs[-1, 0], xticks=[], yticks=[]) ax5 = fig.add_subplot(gs[-1, -2], xticks=[], yticks=[]) -plt.savefig("../figures/layout-gridspec-color.pdf") +fig.savefig(ROOT_DIR / "figures/layout-gridspec-color.pdf") fig.clear() # Inset axes @@ -70,7 +75,7 @@ margin = 0.0125 ax1 = fig.add_axes([margin, margin, 1-2*margin, 1-2*margin], xticks=[], yticks=[]) ax2 = ax1.inset_axes([0.5, 0.5, 0.4, 0.4], xticks=[], yticks=[]) -plt.savefig("../figures/layout-inset.pdf") +fig.savefig(ROOT_DIR / "figures/layout-inset.pdf") fig.clear() @@ -82,4 +87,4 @@ cax = divider.new_horizontal(size="10%", pad=0.025) fig.add_axes(cax) cax.set_xticks([]), cax.set_yticks([]) -plt.savefig("../figures/layout-divider.pdf") +fig.savefig(ROOT_DIR / "figures/layout-divider.pdf") diff --git a/scripts/legend.py b/scripts/legend.py index 5269ff9..ebcbb7c 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -2,11 +2,15 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(4, 4)) ax = fig.add_axes([0.15, 0.15, .7, .7], frameon=True, aspect=1, xticks=[], yticks=[]) @@ -49,5 +53,5 @@ def point(x, y): plt.xlim(0, 1), plt.ylim(0, 1) -plt.savefig("../figures/legend-placement.pdf") +fig.savefig(ROOT_DIR / "figures/legend-placement.pdf") # plt.show() diff --git a/scripts/linestyles.py b/scripts/linestyles.py index b1c619e..e8f9750 100644 --- a/scripts/linestyles.py +++ b/scripts/linestyles.py @@ -2,10 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(4.25, 2*.55)) ax = fig.add_axes([0, 0, 1, 1], xlim=[0.75, 10.25], ylim=[0.5, 2.5], frameon=False, xticks=[], yticks=[]) @@ -53,5 +57,5 @@ def split(n_segment): size=14, ha="left", va="baseline") -plt.savefig("../figures/linestyles.pdf", dpi=200) +fig.savefig(ROOT_DIR / "figures/linestyles.pdf", dpi=200) # plt.show() diff --git a/scripts/markers.py b/scripts/markers.py index 50c5e36..4619b9d 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -2,10 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + # Markers # ----------------------------------------------------------------------------- fig = plt.figure(figsize=(3.5, 1.5)) @@ -52,4 +56,4 @@ plt.text(.7, 1, "markevery", size="medium", ha="left", va="center", family="Source Code Pro") -plt.savefig("../figures/markers.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/markers.pdf", dpi=600) diff --git a/scripts/plot-variations.py b/scripts/plot-variations.py index ad4cc30..cf98d01 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -4,10 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(0.4, 0.4)) mpl.rcParams['axes.linewidth'] = 0.5 mpl.rcParams['xtick.major.size'] = 0.0 @@ -23,7 +28,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-color.pdf") +fig.savefig(ROOT_DIR / "figures/plot-color.pdf") fig.clear() # Basic line plot (linestyle) @@ -35,7 +40,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-linestyle.pdf") +fig.savefig(ROOT_DIR / "figures/plot-linestyle.pdf") fig.clear() # Basic line plot (linewidth) @@ -47,7 +52,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-linewidth.pdf") +fig.savefig(ROOT_DIR / "figures/plot-linewidth.pdf") fig.clear() # Basic line plot (marker) @@ -59,7 +64,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-marker.pdf") +fig.savefig(ROOT_DIR / "figures/plot-marker.pdf") fig.clear() # Basic line plot (multi) @@ -73,7 +78,7 @@ 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.grid(linewidth=0.125) -plt.savefig("../figures/plot-multi.pdf") +fig.savefig(ROOT_DIR / "figures/plot-multi.pdf") fig.clear() # Basic line plot (vsplit) @@ -95,7 +100,7 @@ ax2.set_ylim(0, 4), ax2.set_yticks(np.arange(1, 4)), ax2.set_yticklabels([]) ax2.grid(linewidth=0.125) ax2.tick_params(axis=u'both', which=u'both', length=0) -plt.savefig("../figures/plot-vsplit.pdf") +fig.savefig(ROOT_DIR / "figures/plot-vsplit.pdf") fig.clear() # Basic line plot (hsplit) @@ -117,7 +122,7 @@ ax2.set_ylim(0, 8), ax2.set_yticks(np.arange(1, 8)), ax2.set_yticklabels([]) ax2.grid(linewidth=0.125) ax2.tick_params(axis=u'both', which=u'both', length=0) -plt.savefig("../figures/plot-hsplit.pdf") +fig.savefig(ROOT_DIR / "figures/plot-hsplit.pdf") fig.clear() # Basic line plot (title) @@ -131,7 +136,7 @@ ax.grid(linewidth=0.125) ax.text(4, 6.75, "A Sine wave", transform=ax.transData, clip_on=False, weight="bold", size=4, ha="center", va="center") -plt.savefig("../figures/plot-title.pdf") +fig.savefig(ROOT_DIR / "figures/plot-title.pdf") fig.clear() @@ -147,5 +152,5 @@ ax.text(4, -1, "Time", transform=ax.transData, clip_on=False, size=3.5, ha="center", va="center") # plt.show() -plt.savefig("../figures/plot-xlabel.pdf") +fig.savefig(ROOT_DIR / "figures/plot-xlabel.pdf") fig.clear() diff --git a/scripts/projections.py b/scripts/projections.py index a262050..fce69ec 100644 --- a/scripts/projections.py +++ b/scripts/projections.py @@ -2,12 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import cartopy import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = Path(__file__).parent.parent + CARTOPY_SOURCE_TEMPLATE = 'https://naturalearth.s3.amazonaws.com/{resolution}_{category}/ne_{resolution}_{name}.zip' @@ -34,7 +38,7 @@ ax.set_yticklabels([]) ax.set_ylim(0, 2) ax.grid(linewidth=1) -plt.savefig("../figures/projection-polar.pdf") +fig.savefig(ROOT_DIR / "figures/projection-polar.pdf") fig.clear() # 3D plot @@ -53,7 +57,7 @@ ax.set_xticks([]) ax.set_yticks([]) ax.set_zticks([]) -plt.savefig("../figures/projection-3d.pdf") +fig.savefig(ROOT_DIR / "figures/projection-3d.pdf") fig.clear() # Cartopy plot @@ -64,4 +68,4 @@ projection=cartopy.crs.Orthographic()) ax.add_feature(cartopy.feature.LAND, zorder=0, facecolor="C1", edgecolor="0.0", linewidth=0) -plt.savefig("../figures/projection-cartopy.pdf") +fig.savefig(ROOT_DIR / "figures/projection-cartopy.pdf") diff --git a/scripts/scales.py b/scripts/scales.py index 7520d00..355320b 100644 --- a/scripts/scales.py +++ b/scripts/scales.py @@ -1,6 +1,11 @@ +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(0.4, 2/3*0.4)) ax = fig.add_axes([0, 0, 1, 1], frameon=False) ax.tick_params(axis='both', which='both', length=0) @@ -19,7 +24,7 @@ ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "+∞", ha="right", va="bottom", size=3, transform=ax.transAxes) ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) -plt.savefig("../figures/scale-linear.pdf") +fig.savefig(ROOT_DIR / "figures/scale-linear.pdf") ax.clear() # Log scale @@ -31,7 +36,7 @@ ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "+∞", ha="right", va="bottom", size=3, transform=ax.transAxes) ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) -plt.savefig("../figures/scale-log.pdf") +fig.savefig(ROOT_DIR / "figures/scale-log.pdf") ax.clear() # Symlog scale @@ -43,7 +48,7 @@ ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "+∞", ha="right", va="bottom", size=3, transform=ax.transAxes) ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) -plt.savefig("../figures/scale-symlog.pdf") +fig.savefig(ROOT_DIR / "figures/scale-symlog.pdf") ax.clear() # Symlog scale @@ -55,5 +60,5 @@ ax.text(0, 0.15, "⇤", ha="left", va="top", size=4, transform=ax.transAxes) ax.text(1, 0.12, "1", ha="right", va="bottom", size=3, transform=ax.transAxes) ax.text(1, 0.15, "⇥", ha="right", va="top", size=4, transform=ax.transAxes) -plt.savefig("../figures/scale-logit.pdf") +fig.savefig(ROOT_DIR / "figures/scale-logit.pdf") ax.clear() diff --git a/scripts/sine.py b/scripts/sine.py index c31c49f..0e05c01 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -2,9 +2,14 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + X = np.linspace(0.1, 10*np.pi, 10000) Y = np.sin(X) @@ -12,14 +17,14 @@ plt.plot(X, Y, color="orange", linewidth=2) # plt.xticks([]), plt.yticks([]) plt.tight_layout() -plt.savefig("../figures/sine.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/sine.pdf", dpi=100) fig = plt.figure(figsize=(7, 1.5)) plt.plot(X, Y, "C1o:", markevery=500, mec="1.0", lw=2, ms=8.5, mew=2) # plt.xticks([]), plt.yticks([]) plt.ylim(-1.5, 1.5) plt.tight_layout() -plt.savefig("../figures/sine-marker.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/sine-marker.pdf", dpi=100) fig, ax = plt.subplots(figsize=(7, 1.5)) ax.set_xscale("log") @@ -28,7 +33,7 @@ # plt.xticks([]), plt.yticks([]) plt.ylim(-1.5, 1.5) plt.tight_layout() -plt.savefig("../figures/sine-logscale.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/sine-logscale.pdf", dpi=100) fig = plt.figure(figsize=(7, 1.5)) @@ -38,7 +43,7 @@ # plt.xticks([]), plt.yticks([]) plt.ylim(-1.5, 1.5) plt.tight_layout() -plt.savefig("../figures/sine-period.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/sine-period.pdf", dpi=100) # plt.show() @@ -51,7 +56,7 @@ plt.xticks([]), plt.yticks([]) plt.ylim(-1.25, 1.25) plt.tight_layout() -plt.savefig("../figures/sine-legend.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/sine-legend.pdf", dpi=100) # plt.show() @@ -68,5 +73,5 @@ plt.annotate(" ", (X[300], Y[300]), (X[250], -1), ha="center", va="center", arrowprops={"arrowstyle" : "->", "color": "C1"}) plt.tight_layout() -plt.savefig("../figures/sine-annotate.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/sine-annotate.pdf", dpi=100) # plt.show() diff --git a/scripts/styles.py b/scripts/styles.py index 94ff839..296e8af 100644 --- a/scripts/styles.py +++ b/scripts/styles.py @@ -2,10 +2,15 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + for style in ['default'] + plt.style.available: with plt.style.context(style): fig = plt.figure(figsize=(5, 3), dpi=100) @@ -15,5 +20,5 @@ ax.plot(X, Y) plt.title(style, family="Source Serif Pro", size=32) plt.tight_layout() - plt.savefig("../figures/style-%s.pdf" % style) + fig.savefig(ROOT_DIR / f"figures/style-{style}.pdf") plt.close(fig) diff --git a/scripts/text-alignments.py b/scripts/text-alignments.py index c329ae0..dd525b9 100644 --- a/scripts/text-alignments.py +++ b/scripts/text-alignments.py @@ -2,9 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + dpi = 100 fig = plt.figure(figsize=(4.25, 1.5), dpi=dpi) ax = fig.add_axes([0, 0, 1, 1], frameon=False, @@ -66,5 +71,5 @@ plt.text(P[8, 0]-epsilon, P[8, 1]+epsilon, "(1,1)", color=color, ha="right", va="bottom", size="x-small") -plt.savefig("../figures/text-alignments.pdf") +fig.savefig(ROOT_DIR / "figures/text-alignments.pdf") # plt.show() diff --git a/scripts/tick-formatters.py b/scripts/tick-formatters.py index fe5bb40..ff688ce 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -3,12 +3,16 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +from pathlib import Path + import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = Path(__file__).parent.parent + +# Setup a plot such that only the bottom spine is shown def setup(ax): """Set up Axes with just an x-Axis.""" ax.spines['right'].set_color('none') @@ -107,5 +111,5 @@ def major_formatter(x, pos): # bottom spine. fig.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) -plt.savefig("../figures/tick-formatters.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tick-formatters.pdf", transparent=True) # plt.show() diff --git a/scripts/tick-locators.py b/scripts/tick-locators.py index 276f8a3..6d799e8 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -3,13 +3,17 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = Path(__file__).parent.parent + +# Setup a plot such that only the bottom spine is shown def setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') @@ -103,5 +107,5 @@ def setup(ax): # bottom spine. plt.subplots_adjust(left=0.05, right=0.95, bottom=0.05, top=1.05) -plt.savefig("../figures/tick-locators.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tick-locators.pdf", transparent=True) # plt.show() diff --git a/scripts/tick-multiple-locator.py b/scripts/tick-multiple-locator.py index 771e2fe..1d3dddc 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -3,13 +3,17 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = Path(__file__).parent.parent + +# Setup a plot such that only the bottom spine is shown def setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') @@ -49,5 +53,5 @@ def setup(ax): ax.tick_params(axis='x', which='minor', rotation=90) plt.tight_layout() -plt.savefig("../figures/tick-multiple-locator.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tick-multiple-locator.pdf", transparent=True) # plt.show() diff --git a/scripts/tip-color-range.py b/scripts/tip-color-range.py index b8b43eb..f0c1a99 100644 --- a/scripts/tip-color-range.py +++ b/scripts/tip-color-range.py @@ -4,10 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 @@ -20,5 +25,5 @@ colors = [cmap(i) for i in [.1, .3, .5, .7]] ax.hist(X, 2, density=True, histtype='bar', color=colors) -plt.savefig("../figures/tip-color-range.pdf") +fig.savefig(ROOT_DIR / "figures/tip-color-range.pdf") # plt.show() diff --git a/scripts/tip-colorbar.py b/scripts/tip-colorbar.py index 2a46357..bd0b9b5 100644 --- a/scripts/tip-colorbar.py +++ b/scripts/tip-colorbar.py @@ -4,11 +4,16 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(2.15, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 @@ -21,5 +26,5 @@ cb = fig.colorbar(im, fraction=0.046, pad=0.04) cb.set_ticks([]) -plt.savefig("../figures/tip-colorbar.pdf") +fig.savefig(ROOT_DIR / "figures/tip-colorbar.pdf") # plt.show() diff --git a/scripts/tip-dotted.py b/scripts/tip-dotted.py index ebfae99..6385fb6 100644 --- a/scripts/tip-dotted.py +++ b/scripts/tip-dotted.py @@ -4,9 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(5, .25)) ax = fig.add_axes([0, 0, 1, 1], frameon=False, @@ -17,5 +23,5 @@ ls=(.5, (epsilon, 1)), dash_capstyle="round") plt.plot([0, 1], [1, 1], "black", clip_on=False, lw=8, ls=(-.5, (epsilon, 2)), dash_capstyle="round") -plt.savefig("../figures/tip-dotted.pdf") +fig.savefig(ROOT_DIR / "figures/tip-dotted.pdf") # plt.show() diff --git a/scripts/tip-dual-axis.py b/scripts/tip-dual-axis.py index 74677eb..a49504c 100644 --- a/scripts/tip-dual-axis.py +++ b/scripts/tip-dual-axis.py @@ -1,9 +1,14 @@ +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -mpl.rcParams['axes.linewidth'] = 1.5 +ROOT_DIR = Path(__file__).parent.parent + +mpl.rcParams['axes.linewidth'] = 1.5 + fig = plt.figure(figsize=(2, 2)) d = 0.01 ax1 = fig.add_axes([d, d, 1-2*d, 1-2*d], label="cartesian") @@ -21,5 +26,5 @@ ax2.set_xticklabels([]) ax2.set_yticklabels([]) -plt.savefig("../figures/tip-dual-axis.pdf") +fig.savefig(ROOT_DIR / "figures/tip-dual-axis.pdf") # plt.show() diff --git a/scripts/tip-font-family.py b/scripts/tip-font-family.py index 8689b3b..84b02ea 100644 --- a/scripts/tip-font-family.py +++ b/scripts/tip-font-family.py @@ -3,13 +3,17 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = Path(__file__).parent.parent + +# Setup a plot such that only the bottom spine is shown def setup(ax): ax.spines['right'].set_color('none') ax.spines['left'].set_color('none') @@ -46,5 +50,5 @@ def setup(ax): tick.set_fontname("Roboto Condensed") plt.tight_layout() -plt.savefig("../figures/tip-font-family.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tip-font-family.pdf", transparent=True) # plt.show() diff --git a/scripts/tip-hatched.py b/scripts/tip-hatched.py index c8a4ec3..0ab165b 100644 --- a/scripts/tip-hatched.py +++ b/scripts/tip-hatched.py @@ -1,6 +1,11 @@ +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + cmap = plt.get_cmap("Oranges") color1, color2 = cmap(0.3), cmap(0.5) @@ -36,5 +41,5 @@ ax.spines['top'].set_visible(False) plt.tight_layout() -plt.savefig("../figures/tip-hatched.pdf") +fig.savefig(ROOT_DIR / "figures/tip-hatched.pdf") # plt.show() diff --git a/scripts/tip-multiline.py b/scripts/tip-multiline.py index 1b62b76..59bd68b 100644 --- a/scripts/tip-multiline.py +++ b/scripts/tip-multiline.py @@ -2,9 +2,15 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + + +ROOT_DIR = Path(__file__).parent.parent + mpl.rcParams['axes.linewidth'] = 1.5 fig = plt.figure(figsize=(8, 1.5)) @@ -20,5 +26,5 @@ plt.xlim(-0.25, 10*np.pi+.25) plt.ylim(-1.5, 1.5) plt.tight_layout() -plt.savefig("../figures/tip-multiline.pdf", dpi=100) +fig.savefig(ROOT_DIR / "figures/tip-multiline.pdf", dpi=100) # plt.show() diff --git a/scripts/tip-outline.py b/scripts/tip-outline.py index e376149..108dfc5 100644 --- a/scripts/tip-outline.py +++ b/scripts/tip-outline.py @@ -4,11 +4,16 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects + +ROOT_DIR = Path(__file__).parent.parent + fig = plt.figure(figsize=(2, 2)) mpl.rcParams['axes.linewidth'] = 1.5 d = 0.01 @@ -24,4 +29,4 @@ color=cmap(0.9), size=32, weight="bold", ha="center", va="bottom") text.set_path_effects([path_effects.Stroke(linewidth=5, foreground='white'), path_effects.Normal()]) -plt.savefig("../figures/tip-outline.pdf") +fig.savefig(ROOT_DIR / "figures/tip-outline.pdf") diff --git a/scripts/tip-post-processing.py b/scripts/tip-post-processing.py index 4086d03..0f12854 100644 --- a/scripts/tip-post-processing.py +++ b/scripts/tip-post-processing.py @@ -1,9 +1,14 @@ +from pathlib import Path + import numpy as np import matplotlib.pyplot as plt from matplotlib.figure import Figure from matplotlib.backends.backend_agg import FigureCanvas from scipy.ndimage import gaussian_filter + +ROOT_DIR = Path(__file__).parent.parent + # First pass for drop-shadow fig = Figure(figsize=(6, 1.5)) canvas = FigureCanvas(fig) @@ -23,5 +28,5 @@ ax.text(0.5, 0.5, "Matplotlib", transform=ax.transAxes, ha="center", va="center", size=64, color="black") -plt.savefig("../figures/tip-post-processing.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/tip-post-processing.pdf", dpi=600) # plt.show() diff --git a/scripts/tip-transparency.py b/scripts/tip-transparency.py index 2d9abc6..920396f 100644 --- a/scripts/tip-transparency.py +++ b/scripts/tip-transparency.py @@ -2,9 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +from pathlib import Path + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = Path(__file__).parent.parent + mpl.rc('axes', linewidth=1.5) np.random.seed(123) @@ -21,5 +26,5 @@ ax.set_xlim([-1, 1]), ax.set_xticks([]), ax.set_ylim([-1, 1]), ax.set_yticks([]) -plt.savefig("../figures/tip-transparency.pdf") +fig.savefig(ROOT_DIR / "figures/tip-transparency.pdf") # plt.show()