Skip to content

Commit

Permalink
Save figures in a path relative to the script
Browse files Browse the repository at this point in the history
This allows running them from the `scripts` directory, _or_ the top of
the checkout.
  • Loading branch information
QuLogic committed Mar 29, 2023
1 parent 3d7d3ff commit 6a080d5
Show file tree
Hide file tree
Showing 37 changed files with 259 additions and 87 deletions.
6 changes: 5 additions & 1 deletion scripts/adjustements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


REPO = 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=[])
Expand Down Expand Up @@ -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(REPO / "figures/adjustments.pdf")
# plt.show()
23 changes: 14 additions & 9 deletions scripts/advanced-plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


REPO = 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
Expand All @@ -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(REPO / "figures/advanced-step.pdf")
ax.clear()

# Violin plot
Expand All @@ -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(REPO / "figures/advanced-violin.pdf")
ax.clear()

# Boxplot
Expand All @@ -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(REPO / "figures/advanced-boxplot.pdf")
ax.clear()

# Barbs plot
Expand All @@ -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(REPO / "figures/advanced-barbs.pdf")
ax.clear()

# Event plot
Expand All @@ -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(REPO / "figures/advanced-event.pdf")
ax.clear()

# Errorbar plot
Expand All @@ -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(REPO / "figures/advanced-errorbar.pdf")
ax.clear()

# Hexbin plot
Expand All @@ -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(REPO / "figures/advanced-hexbin.pdf")
ax.clear()

# Hist plot
Expand All @@ -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(REPO / "figures/advanced-hist.pdf")
ax.clear()

# Xcorr plot
Expand All @@ -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(REPO / "figures/advanced-xcorr.pdf")
ax.clear()
8 changes: 7 additions & 1 deletion scripts/anatomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


REPO = Path(__file__).parent.parent

np.random.seed(123)

X = np.linspace(0.5, 3.5, 100)
Expand Down Expand Up @@ -136,5 +142,5 @@ def text(x, y, text):
connectionstyle="arc3",
color=color))

plt.savefig("../figures/anatomy.pdf")
fig.savefig(REPO / "figures/anatomy.pdf")
# plt.show()
6 changes: 5 additions & 1 deletion scripts/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


REPO = Path(__file__).parent.parent

fig = plt.figure(figsize=(6, 1))
# ax = plt.subplot(111, frameon=False, aspect=.1)
# b = 0.0
Expand All @@ -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(REPO / "figures/annotate.pdf")
# plt.show()
7 changes: 6 additions & 1 deletion scripts/annotation-arrow-styles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from pathlib import Path

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches


REPO = Path(__file__).parent.parent

styles = mpatches.ArrowStyle.get_styles()


Expand Down Expand Up @@ -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(REPO / "figures/annotation-arrow-styles.pdf")
# plt.show()
7 changes: 6 additions & 1 deletion scripts/annotation-connection-styles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from pathlib import Path

import matplotlib.pyplot as plt


REPO = Path(__file__).parent.parent


def demo_con_style(ax, connectionstyle):
x1, y1 = 0.3, 0.2
x2, y2 = 0.8, 0.6
Expand Down Expand Up @@ -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(REPO / "figures/annotation-connection-styles.pdf")
# plt.show()
27 changes: 16 additions & 11 deletions scripts/basic-plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


REPO = 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
Expand All @@ -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(REPO / "figures/basic-plot.pdf")
ax.clear()

# Basic line plot (color)blaPwd
Expand All @@ -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(REPO / "figures/basic-plot-color.pdf")
ax.clear()

# Basic scatter plot
Expand All @@ -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(REPO / "figures/basic-scatter.pdf")
ax.clear()

# Basic bar plot
Expand All @@ -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(REPO / "figures/basic-bar.pdf")
ax.clear()

# Basic imshow plot
Expand All @@ -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(REPO / "figures/basic-imshow.pdf")
ax.clear()

# Basic pcolormesh plot
Expand All @@ -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(REPO / "figures/basic-pcolormesh.pdf")
ax.clear()

# Basic contour plot
Expand All @@ -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(REPO / "figures/basic-contour.pdf")
ax.clear()

# Basic pie plot
Expand All @@ -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(REPO / "figures/basic-pie.pdf")
ax.clear()

# Basic text plot
Expand All @@ -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(REPO / "figures/basic-text.pdf")
ax.clear()

# Basic fill plot
Expand All @@ -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(REPO / "figures/basic-fill.pdf")
ax.clear()

# Basic quiver plot
Expand All @@ -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(REPO / "figures/basic-quiver.pdf")
ax.clear()
7 changes: 6 additions & 1 deletion scripts/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


REPO = Path(__file__).parent.parent

fig = plt.figure(figsize=(6, .65))
# ax = plt.subplot(111, frameon=False, aspect=.1)
b = 0.025
Expand All @@ -19,5 +24,5 @@
plt.colorbar(sm, cax=ax, ticks=np.linspace(0, 1, 11),
orientation="horizontal")

plt.savefig("../figures/colorbar.pdf")
fig.savefig(REPO / "figures/colorbar.pdf")
# plt.show()
6 changes: 5 additions & 1 deletion scripts/colormaps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from pathlib import Path

import numpy as np
import matplotlib.pyplot as plt


REPO = 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)
Expand Down Expand Up @@ -62,5 +66,5 @@
family = "Source Pro Serif", size=10, ha="center", va="center")
"""

plt.savefig("../figures/colormap-%s.pdf" % cmap)
fig.savefig(REPO / f"figures/colormap-{cmap}.pdf")
ax.clear()
7 changes: 5 additions & 2 deletions scripts/colornames.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


REPO = Path(__file__).parent.parent

colors = dict(mcolors.BASE_COLORS, **mcolors.CSS4_COLORS)

# Sort colors by hue, saturation, value and name.
Expand Down Expand Up @@ -53,5 +56,5 @@
top=1, bottom=0,
hspace=0, wspace=0)

plt.savefig("../figures/colornames.pdf")
fig.savefig(REPO / "figures/colornames.pdf")
# plt.show()
Loading

0 comments on commit 6a080d5

Please sign in to comment.