Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save figures in a path relative to the script #127

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions scripts/adjustements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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")
24 changes: 13 additions & 11 deletions scripts/advanced-plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])


Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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")
7 changes: 4 additions & 3 deletions scripts/anatomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
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
# -----------------------------------------------------------------------------
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
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(ROOT_DIR / "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 @@
import pathlib

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


ROOT_DIR = pathlib.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(ROOT_DIR / "figures/annotation-arrow-styles.pdf")
# plt.show()
8 changes: 5 additions & 3 deletions scripts/annotation-connection-styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
28 changes: 15 additions & 13 deletions scripts/basic-plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
])


Expand All @@ -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)
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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
# -----------------------------------------------------------------------------
Expand All @@ -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")
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
# -----------------------------------------------------------------------------

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

Expand Down Expand Up @@ -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")
7 changes: 6 additions & 1 deletion scripts/colors.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
# -----------------------------------------------------------------------------

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)
Expand Down Expand Up @@ -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()
Loading
Loading