Skip to content

Commit

Permalink
Merge 2b9fac6 into f698572
Browse files Browse the repository at this point in the history
  • Loading branch information
mathematicalmichael committed Jan 22, 2024
2 parents f698572 + 2b9fac6 commit 39a6f89
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,32 @@ jobs:

- name: New CLI
run: mud examples mud-paper

texless-integration-tests:
name: texless cli examples
strategy:
matrix:
python-version: ["3.9"]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install Python dependencies
run: |
pip install --upgrade pip
pip install --upgrade mud-examples
pip install .[examples]
- name: Old CLI
run: mud_run_all -v

- name: New CLI
run: mud examples mud-paper
54 changes: 30 additions & 24 deletions src/mud/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
---------
"""
from logging import getLogger
from pathlib import Path

import numpy as np
Expand All @@ -16,7 +17,34 @@

from mud.util import null_space

_logger = getLogger(__name__)


def _check_latex():
"""check latex installation"""

path = Path.cwd() / ".test_fig.png"
try: # minimal example to trip up matplotlib
plt.rcParams.update({"text.usetex": True})
plt.plot([0], [1], label=r"$a_\text{foo} = \lambda$")
plt.plot([0, 1], [1, 2], label="Something")
plt.savefig(str(path), bbox_inches="tight")
path.unlink(missing_ok=True)
_logger.info("USING TEX")
return True
except (RuntimeError, FileNotFoundError):
_logger.warning("NOT USING TEX")
return False


# Matplotlib plotting options
HAS_LATEX = _check_latex()
PREAMBLE = ""
if HAS_LATEX:
PREAMBLE = " ".join(
[r"\usepackage{bm}", r"\usepackage{amsfonts}", r"\usepackage{amsmath}"]
)

mud_plot_params = {
"mathtext.fontset": "stix",
"font.family": "STIXGeneral",
Expand All @@ -29,31 +57,12 @@
"axes.labelpad": 1,
"font.size": 16,
"savefig.facecolor": "white",
"text.usetex": True,
"text.latex.preamble": " ".join(
[r"\usepackage{bm}", r"\usepackage{amsfonts}", r"\usepackage{amsmath}"]
),
"text.usetex": HAS_LATEX,
"text.latex.preamble": PREAMBLE,
}
plt.rcParams.update(mud_plot_params)


def _check_latex():
"""check latex installation"""
global mud_plot_params

path = Path.cwd() / ".test_fig.png"
plt.plot([0], [1], label=r"$a_\text{foo} = \lambda$")
try:
plt.legend()
plt.savefig(str(path))
path.unlink(missing_ok=True)
except RuntimeError:
print("NOT USING TEX")
mud_plot_params["text.usetex"] = False
mud_plot_params["text.latex.preamble"] = ""
plt.rcParams.update(mud_plot_params)


def save_figure(
fname: str, save_path: str = "figures", close_fig: bool = True, **kwargs
):
Expand Down Expand Up @@ -227,6 +236,3 @@ def plot_vert_line(ax, x_loc, ylim=None, **kwargs):
ylims[1] = ylim if ylim is not None else ylims[1]
ax.plot([x_loc, x_loc], [ylims[0], ylims[1]], **kwargs)
ax.set_ylim(ylims)


_check_latex()

0 comments on commit 39a6f89

Please sign in to comment.