From 7f40833acc5dfea5dc062c92fcfc333b3099f164 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 | 7 ++++--- scripts/advanced-plots.py | 24 +++++++++++---------- scripts/anatomy.py | 7 ++++--- scripts/annotate.py | 6 +++++- scripts/annotation-arrow-styles.py | 7 ++++++- scripts/annotation-connection-styles.py | 8 ++++--- scripts/basic-plots.py | 28 +++++++++++++------------ scripts/colorbar.py | 7 ++++++- scripts/colormaps.py | 6 +++++- scripts/colornames.py | 6 ++++-- scripts/colors.py | 7 ++++++- scripts/extents.py | 7 ++++--- scripts/fonts.py | 4 +++- scripts/interpolations.py | 9 ++++---- scripts/layouts.py | 19 ++++++++++------- scripts/legend.py | 6 ++++-- scripts/linestyles.py | 6 +++++- scripts/markers.py | 6 +++++- scripts/plot-variations.py | 23 +++++++++++--------- scripts/projections.py | 13 ++++++------ scripts/scales.py | 13 ++++++++---- scripts/sine.py | 19 +++++++++-------- 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, 242 insertions(+), 109 deletions(-) diff --git a/scripts/adjustements.py b/scripts/adjustements.py index f433a69..26f9559 100644 --- a/scripts/adjustements.py +++ b/scripts/adjustements.py @@ -11,8 +11,10 @@ from matplotlib.collections import PatchCollection +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('font', size=4) mpl.rc('lines', linewidth=0.5) @@ -33,7 +35,6 @@ (fig, ax) = plt.subplots(**subplots_kw) - box = mpatches.FancyBboxPatch( (0, 0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2), facecolor="0.9", edgecolor="black") @@ -145,4 +146,4 @@ def int_arrow(p0, p1): rotation="vertical", ha="center", va="center") -plt.savefig("../figures/adjustments.pdf") +fig.savefig(ROOT_DIR / "figures/adjustments.pdf") diff --git a/scripts/advanced-plots.py b/scripts/advanced-plots.py index 4d86ba0..f598087 100644 --- a/scripts/advanced-plots.py +++ b/scripts/advanced-plots.py @@ -11,9 +11,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) @@ -29,7 +31,7 @@ Y = 4 + 2*np.sin(2*X) ax.step(X, Y, color="C1") ax.grid() -fig.savefig("../figures/advanced-step.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-step.pdf") # Violin plot # ----------------------------------------------------------------------------- @@ -43,7 +45,7 @@ body.set_alpha(1) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-violin.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-violin.pdf") # Boxplot # ----------------------------------------------------------------------------- @@ -63,7 +65,7 @@ "linewidth": 0.75}) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-boxplot.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-boxplot.pdf") # Barbs plot # ----------------------------------------------------------------------------- @@ -76,7 +78,7 @@ ax.barbs(X, Y, U, V, barbcolor="C1", flagcolor="C1", length=5, linewidth=0.5) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-barbs.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-barbs.pdf") # Event plot # ----------------------------------------------------------------------------- @@ -88,7 +90,7 @@ linewidth=0.25) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-event.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-event.pdf") # Errorbar plot # ----------------------------------------------------------------------------- @@ -100,7 +102,7 @@ ax.errorbar(X, Y, E, color="C1", linewidth=0.75, capsize=1) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-errorbar.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-errorbar.pdf") # Hexbin plot # ----------------------------------------------------------------------------- @@ -113,7 +115,7 @@ cmap=plt.get_cmap("Wistia"), alpha=1.0) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-hexbin.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-hexbin.pdf") # Hist plot # ----------------------------------------------------------------------------- @@ -124,7 +126,7 @@ ax.set_ylim(0, 80), ax.set_yticks(np.arange(1, 80, 10)) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-hist.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-hist.pdf") # Xcorr plot # ----------------------------------------------------------------------------- @@ -138,4 +140,4 @@ ax.set_ylim(-.25, .25), ax.set_yticks(np.linspace(-.25, .25, 9)) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/advanced-xcorr.pdf") +fig.savefig(ROOT_DIR / "figures/advanced-xcorr.pdf") diff --git a/scripts/anatomy.py b/scripts/anatomy.py index a79037e..e8f95cc 100644 --- a/scripts/anatomy.py +++ b/scripts/anatomy.py @@ -11,11 +11,12 @@ from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) - np.random.seed(123) X = np.linspace(0.5, 3.5, 100) @@ -144,5 +145,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..6535368 100644 --- a/scripts/annotate.py +++ b/scripts/annotate.py @@ -2,11 +2,15 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = pathlib.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..26ac950 100644 --- a/scripts/annotation-arrow-styles.py +++ b/scripts/annotation-arrow-styles.py @@ -1,6 +1,11 @@ +import pathlib + import matplotlib.pyplot as plt import matplotlib.patches as mpatches + +ROOT_DIR = pathlib.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 81908d7..057b5cd 100644 --- a/scripts/annotation-connection-styles.py +++ b/scripts/annotation-connection-styles.py @@ -4,9 +4,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet-grid.mplstyle', ]) mpl.rc('lines', markersize=3) @@ -41,4 +43,4 @@ def demo_con_style(ax, connectionstyle): for ax in axs.flat: ax.set(xlim=(0, 1), ylim=(0, 1), xticks=[], yticks=[], aspect=1) -plt.savefig("../figures/annotation-connection-styles.pdf") +fig.savefig(ROOT_DIR / "figures/annotation-connection-styles.pdf") diff --git a/scripts/basic-plots.py b/scripts/basic-plots.py index 5dd8598..8350326 100644 --- a/scripts/basic-plots.py +++ b/scripts/basic-plots.py @@ -11,9 +11,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) @@ -29,7 +31,7 @@ Y = 4 + 2*np.sin(2*X) ax.plot(X, Y, color="C1") ax.grid() -fig.savefig("../figures/basic-plot.pdf") +fig.savefig(ROOT_DIR / "figures/basic-plot.pdf") # Basic line plot (color) # ----------------------------------------------------------------------------- @@ -38,7 +40,7 @@ Y = 4 + 2*np.sin(2*X) ax.plot(X, Y, color="black") ax.grid() -fig.savefig("../figures/basic-plot-color.pdf") +fig.savefig(ROOT_DIR / "figures/basic-plot-color.pdf") # Basic scatter plot # ----------------------------------------------------------------------------- @@ -49,7 +51,7 @@ ax.scatter(X, Y, 5, zorder=10, edgecolor="white", facecolor="C1", linewidth=0.25) ax.grid() -fig.savefig("../figures/basic-scatter.pdf") +fig.savefig(ROOT_DIR / "figures/basic-scatter.pdf") # Basic bar plot # ----------------------------------------------------------------------------- @@ -61,7 +63,7 @@ edgecolor="white", facecolor="C1", linewidth=0.25) ax.set_axisbelow(True) ax.grid() -fig.savefig("../figures/basic-bar.pdf") +fig.savefig(ROOT_DIR / "figures/basic-bar.pdf") # Basic imshow plot # ----------------------------------------------------------------------------- @@ -72,7 +74,7 @@ Z[..., 3] = np.random.uniform(0.25, 1.0, (8, 8)) ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest") ax.grid(linewidth=0.25, color="white") -fig.savefig("../figures/basic-imshow.pdf") +fig.savefig(ROOT_DIR / "figures/basic-imshow.pdf") # Basic pcolormesh plot # ----------------------------------------------------------------------------- @@ -84,7 +86,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)) -fig.savefig("../figures/basic-pcolormesh.pdf") +fig.savefig(ROOT_DIR / "figures/basic-pcolormesh.pdf") # Basic contour plot # ----------------------------------------------------------------------------- @@ -95,7 +97,7 @@ plt.contourf(Z, len(colors), extent=[0, 8, 0, 8], colors=colors) plt.contour(Z, len(colors), extent=[0, 8, 0, 8], colors="white", linewidths=0.125, nchunk=10) -fig.savefig("../figures/basic-contour.pdf") +fig.savefig(ROOT_DIR / "figures/basic-contour.pdf") # Basic pie plot # ----------------------------------------------------------------------------- @@ -110,7 +112,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) -fig.savefig("../figures/basic-pie.pdf") +fig.savefig(ROOT_DIR / "figures/basic-pie.pdf") # Basic text plot # ----------------------------------------------------------------------------- @@ -119,7 +121,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) -fig.savefig("../figures/basic-text.pdf") +fig.savefig(ROOT_DIR / "figures/basic-text.pdf") # Basic fill plot # ----------------------------------------------------------------------------- @@ -132,7 +134,7 @@ plt.plot(X, (Y1+Y2)/2, color="C1", linewidth=0.5) ax.set_axisbelow(True) ax.grid(color="0.75") -fig.savefig("../figures/basic-fill.pdf") +fig.savefig(ROOT_DIR / "figures/basic-fill.pdf") # Basic quiver plot # ----------------------------------------------------------------------------- @@ -145,4 +147,4 @@ angles='xy', scale_units='xy', scale=0.5, width=.05) ax.set_axisbelow(True) ax.grid(color="0.75") -fig.savefig("../figures/basic-quiver.pdf") +fig.savefig(ROOT_DIR / "figures/basic-quiver.pdf") diff --git a/scripts/colorbar.py b/scripts/colorbar.py index 495cccc..6ffba8f 100644 --- a/scripts/colorbar.py +++ b/scripts/colorbar.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- + +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = pathlib.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..8858299 100644 --- a/scripts/colormaps.py +++ b/scripts/colormaps.py @@ -1,7 +1,11 @@ +import pathlib + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = pathlib.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 d88d381..a059787 100644 --- a/scripts/colornames.py +++ b/scripts/colornames.py @@ -11,8 +11,10 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('figure.constrained_layout', h_pad=0, w_pad=0, hspace=0, wspace=0) @@ -54,4 +56,4 @@ ax.set_ylim(0, Y) ax.set_axis_off() -plt.savefig("../figures/colornames.pdf") +fig.savefig(ROOT_DIR / "figures/colornames.pdf") diff --git a/scripts/colors.py b/scripts/colors.py index 9d323e3..1bd76f8 100644 --- a/scripts/colors.py +++ b/scripts/colors.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- + +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt +ROOT_DIR = pathlib.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 c3bec1d..2eab814 100644 --- a/scripts/extents.py +++ b/scripts/extents.py @@ -9,12 +9,13 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('figure.constrained_layout', wspace=0.05) - Z = np.arange(5*5).reshape(5, 5) (fig, axs) = plt.subplots(figsize=(8, 5), nrows=2, ncols=2) @@ -64,4 +65,4 @@ ax.text(5.0, -0.5, "extent=[10,0,0,5]", ha="center", va="center", color="black", size="large") -plt.savefig("../figures/extents.pdf", dpi=600) +fig.savefig(ROOT_DIR / "figures/extents.pdf", dpi=600) diff --git a/scripts/fonts.py b/scripts/fonts.py index 9766453..7d39e10 100644 --- a/scripts/fonts.py +++ b/scripts/fonts.py @@ -7,6 +7,8 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.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]) @@ -105,5 +107,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 783d26c..3cd1308 100644 --- a/scripts/interpolations.py +++ b/scripts/interpolations.py @@ -5,12 +5,13 @@ import numpy as np +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet-grid.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet-grid.mplstyle', ]) - methods = [None, 'none', 'nearest', 'bilinear', 'bicubic', 'spline16', 'spline36', 'hanning', 'hamming', 'hermite', 'kaiser', 'quadric', 'catrom', 'gaussian', 'bessel', 'mitchell', 'sinc', 'lanczos'] @@ -28,5 +29,5 @@ ax.text(0.5, 0.1, str(interp_method), weight="bold", color="white", size=6, ha="center", va="center") -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..49f7340 100644 --- a/scripts/layouts.py +++ b/scripts/layouts.py @@ -2,11 +2,16 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt from mpl_toolkits.axes_grid1 import make_axes_locatable + +ROOT_DIR = pathlib.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 f75f147..5faf885 100644 --- a/scripts/legend.py +++ b/scripts/legend.py @@ -9,8 +9,10 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', ]) mpl.rc('font', size=6) mpl.rc('lines', markersize=4) @@ -63,4 +65,4 @@ def point(x, y): text(1-d, 1+d, "J"), text(0.5, 1+d, "K"), text( d, 1+d, "L") point(1-d+e, 1+d-e), point(0.5, 1+d-e), point(d-e, 1+d-e), -fig.savefig("../figures/legend-placement.pdf") +fig.savefig(ROOT_DIR / "figures/legend-placement.pdf") diff --git a/scripts/linestyles.py b/scripts/linestyles.py index b1c619e..6f9deaa 100644 --- a/scripts/linestyles.py +++ b/scripts/linestyles.py @@ -2,10 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = pathlib.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..48f1d01 100644 --- a/scripts/markers.py +++ b/scripts/markers.py @@ -2,10 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt +ROOT_DIR = pathlib.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 60f9463..65b9ff1 100644 --- a/scripts/plot-variations.py +++ b/scripts/plot-variations.py @@ -10,9 +10,11 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) mpl.rc('axes', titlepad=1) @@ -29,7 +31,7 @@ Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="black", linewidth=0.75) ax.grid() -fig.savefig("../figures/plot-color.pdf") +fig.savefig(ROOT_DIR / "figures/plot-color.pdf") # Basic line plot (linestyle) # ----------------------------------------------------------------------------- @@ -38,7 +40,7 @@ Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75, linestyle="--") ax.grid() -fig.savefig("../figures/plot-linestyle.pdf") +fig.savefig(ROOT_DIR / "figures/plot-linestyle.pdf") # Basic line plot (linewidth) # ----------------------------------------------------------------------------- @@ -48,6 +50,7 @@ ax.plot(X, Y, color="C1", linewidth=1.5) ax.grid() fig.savefig("../figures/plot-linewidth.pdf") +fig.savefig(ROOT_DIR / "figures/plot-linewidth.pdf") # Basic line plot (marker) # ----------------------------------------------------------------------------- @@ -56,7 +59,7 @@ Y = 4+2*np.sin(2*X) ax.plot(X, Y, color="C1", linewidth=0.75, marker="o", markevery=5, markersize=2) ax.grid() -fig.savefig("../figures/plot-marker.pdf") +fig.savefig(ROOT_DIR / "figures/plot-marker.pdf") # Basic line plot (multi) # ----------------------------------------------------------------------------- @@ -67,7 +70,7 @@ ax.plot(X, Y1, color="C1", linewidth=0.75) ax.plot(X, Y2, color="C0", linewidth=0.75) ax.grid() -fig.savefig("../figures/plot-multi.pdf") +fig.savefig(ROOT_DIR / "figures/plot-multi.pdf") # Basic line plot (vsplit) # ----------------------------------------------------------------------------- @@ -85,7 +88,7 @@ ax2.set_ylim(0, 4), ax2.set_yticks(np.arange(1, 4)) ax2.grid() ax2.tick_params(axis=u'both', which=u'both', length=0) -fig.savefig("../figures/plot-vsplit.pdf") +fig.savefig(ROOT_DIR / "figures/plot-vsplit.pdf") # Basic line plot (hsplit) # ----------------------------------------------------------------------------- @@ -103,7 +106,7 @@ ax2.set_xlim(0, 4), ax2.set_xticks(np.arange(1, 4)) ax2.grid() ax2.tick_params(axis=u'both', which=u'both', length=0) -fig.savefig("../figures/plot-hsplit.pdf") +fig.savefig(ROOT_DIR / "figures/plot-hsplit.pdf") # Basic line plot (title) # ----------------------------------------------------------------------------- @@ -114,7 +117,7 @@ ax.set_ylim(0, 6), ax.set_yticks(np.arange(1, 6)) ax.grid() ax.set_title("A Sine wave", size=4, weight="bold") -fig.savefig("../figures/plot-title.pdf") +fig.savefig(ROOT_DIR / "figures/plot-title.pdf") # Basic line plot (xlabel) # ----------------------------------------------------------------------------- @@ -126,4 +129,4 @@ ax.grid() ax.text(4, -1, "Time", transform=ax.transData, clip_on=False, size=3.5, ha="center", va="center") -fig.savefig("../figures/plot-xlabel.pdf") +fig.savefig(ROOT_DIR / "figures/plot-xlabel.pdf") diff --git a/scripts/projections.py b/scripts/projections.py index fde46cb..1f623a9 100644 --- a/scripts/projections.py +++ b/scripts/projections.py @@ -10,12 +10,13 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/plotlet.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/plotlet.mplstyle', ]) - CARTOPY_SOURCE_TEMPLATE = 'https://naturalearth.s3.amazonaws.com/{resolution}_{category}/ne_{resolution}_{name}.zip' @@ -39,7 +40,7 @@ ax.set_yticklabels([]) ax.set_ylim(0, 2) ax.grid(linewidth=0.2) -plt.savefig("../figures/projection-polar.pdf") +fig.savefig(ROOT_DIR / "figures/projection-polar.pdf") fig.clear() # 3D plot @@ -57,7 +58,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 @@ -67,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..70192ca 100644 --- a/scripts/scales.py +++ b/scripts/scales.py @@ -1,6 +1,11 @@ +import pathlib + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.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 6b30775..0e6a347 100644 --- a/scripts/sine.py +++ b/scripts/sine.py @@ -9,31 +9,32 @@ import matplotlib.pyplot as plt +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/sine-plot.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/sine-plot.mplstyle', ]) - X = np.linspace(0.1, 10*np.pi, 10000) Y = np.sin(X) (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.2/2.54)) ax.set_yticks(np.linspace(-1, 1, 5)) ax.plot(X, Y, color="orange") -plt.savefig("../figures/sine.pdf") +fig.savefig(ROOT_DIR / "figures/sine.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) ax.plot(X, Y, "C1o:", markevery=500, mec="1.0") ax.set_ylim(-1.5, 1.5) -fig.savefig("../figures/sine-marker.pdf") +fig.savefig(ROOT_DIR / "figures/sine-marker.pdf") fig, ax = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) ax.set_xscale("log") ax.plot(X, Y, "-") ax.plot(X, Y, "C1o-", markevery=500, mec="1.0") ax.set_ylim(-1.5, 1.5) -fig.savefig("../figures/sine-logscale.pdf") +fig.savefig(ROOT_DIR / "figures/sine-logscale.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) @@ -41,7 +42,7 @@ ax.fill_betweenx([-1.5, 1.5], [0], [2*np.pi], color=".9") ax.text(0, -1, r" Period $\Phi$", va="top") ax.set_ylim(-1.5, 1.5) -fig.savefig("../figures/sine-period.pdf") +fig.savefig(ROOT_DIR / "figures/sine-period.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) @@ -52,7 +53,7 @@ ax.set_title("Sine and Cosine") ax.set_xticks([]), ax.set_yticks([]) ax.set_ylim(-1.25, 1.25) -fig.savefig("../figures/sine-legend.pdf") +fig.savefig(ROOT_DIR / "figures/sine-legend.pdf") (fig, ax) = plt.subplots(figsize=(5.7/2.54, 1.0/2.54)) @@ -66,4 +67,4 @@ arrowprops=dict(arrowstyle="->", color="C1", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5)) ax.annotate(" ", (X[300], Y[300]), (X[250], -1), ha="center", va="center", arrowprops=dict(arrowstyle="->", color="C1", linewidth=0.5, patchA=None, shrinkA=4, shrinkB=0.5)) -fig.savefig("../figures/sine-annotate.pdf") +fig.savefig(ROOT_DIR / "figures/sine-annotate.pdf") diff --git a/scripts/styles.py b/scripts/styles.py index 94ff839..bedf9d9 100644 --- a/scripts/styles.py +++ b/scripts/styles.py @@ -2,10 +2,15 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.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..0d653b9 100644 --- a/scripts/text-alignments.py +++ b/scripts/text-alignments.py @@ -2,9 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.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..bcdce04 100644 --- a/scripts/tick-formatters.py +++ b/scripts/tick-formatters.py @@ -3,12 +3,16 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import matplotlib.pyplot as plt import matplotlib.ticker as ticker -# Setup a plot such that only the bottom spine is shown +ROOT_DIR = pathlib.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..4c0985c 100644 --- a/scripts/tick-locators.py +++ b/scripts/tick-locators.py @@ -3,13 +3,17 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + 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 = pathlib.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 c8a799e..2976a63 100644 --- a/scripts/tick-multiple-locator.py +++ b/scripts/tick-multiple-locator.py @@ -11,9 +11,11 @@ import matplotlib.ticker as ticker +ROOT_DIR = pathlib.Path(__file__).parent.parent + mpl.style.use([ - pathlib.Path(__file__).parent/'../styles/base.mplstyle', - pathlib.Path(__file__).parent/'../styles/ticks.mplstyle', + ROOT_DIR / 'styles/base.mplstyle', + ROOT_DIR / 'styles/ticks.mplstyle', ]) @@ -30,4 +32,4 @@ ax.tick_params(axis='both', which='major', labelsize=5) ax.tick_params(axis='x', which='minor', rotation=90) -plt.savefig("../figures/tick-multiple-locator.pdf", transparent=True) +fig.savefig(ROOT_DIR / "figures/tick-multiple-locator.pdf", transparent=True) diff --git a/scripts/tip-color-range.py b/scripts/tip-color-range.py index b8b43eb..5743940 100644 --- a/scripts/tip-color-range.py +++ b/scripts/tip-color-range.py @@ -4,10 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.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..9e8da79 100644 --- a/scripts/tip-colorbar.py +++ b/scripts/tip-colorbar.py @@ -4,11 +4,16 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects + +ROOT_DIR = pathlib.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..8f52a2c 100644 --- a/scripts/tip-dotted.py +++ b/scripts/tip-dotted.py @@ -4,9 +4,15 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + + +ROOT_DIR = pathlib.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..9d72f34 100644 --- a/scripts/tip-dual-axis.py +++ b/scripts/tip-dual-axis.py @@ -1,9 +1,14 @@ +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt -mpl.rcParams['axes.linewidth'] = 1.5 +ROOT_DIR = pathlib.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..53564ac 100644 --- a/scripts/tip-font-family.py +++ b/scripts/tip-font-family.py @@ -3,13 +3,17 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + 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 = pathlib.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 56ac515..f1a38d4 100644 --- a/scripts/tip-hatched.py +++ b/scripts/tip-hatched.py @@ -1,6 +1,11 @@ +import pathlib + import numpy as np import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.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..99d704c 100644 --- a/scripts/tip-multiline.py +++ b/scripts/tip-multiline.py @@ -2,9 +2,15 @@ # Author: Nicolas P. Rougier # License: BSD # ---------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + + +ROOT_DIR = pathlib.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..6fe1a6f 100644 --- a/scripts/tip-outline.py +++ b/scripts/tip-outline.py @@ -4,11 +4,16 @@ # ----------------------------------------------------------------------------- # Scripts to generate all the basic plots +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.patheffects as path_effects + +ROOT_DIR = pathlib.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..3280efe 100644 --- a/scripts/tip-post-processing.py +++ b/scripts/tip-post-processing.py @@ -1,9 +1,14 @@ +import pathlib + 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 = pathlib.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..320ea0c 100644 --- a/scripts/tip-transparency.py +++ b/scripts/tip-transparency.py @@ -2,9 +2,14 @@ # Matplotlib cheat sheet # Released under the BSD License # ----------------------------------------------------------------------------- +import pathlib + import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt + +ROOT_DIR = pathlib.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()