diff --git a/docs/conf.py b/docs/conf.py index 349e3e0d..020afdb2 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -14,9 +14,6 @@ import sys import warnings -from sphinx_gallery.scrapers import matplotlib_scraper -from sphinx_gallery.sorting import ExampleTitleSortKey - import pyhdtoolkit # ignore numpy warnings, see: @@ -28,7 +25,7 @@ warnings.filterwarnings( "ignore", category=UserWarning, - message="Matplotlib is currently using agg, which is a" " non-GUI backend, so cannot show the figure.", + message="Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.", ) TOPLEVEL_DIR = pathlib.Path(__file__).parent.parent.absolute() @@ -41,14 +38,6 @@ # See: https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#confval-autodoc_type_aliases autodoc_type_aliases = {"ArrayLike": "ArrayLike"} -# To use SVG outputs when scraping matplotlib figures for the sphinx-gallery -class matplotlib_svg_scraper: - def __repr__(self): - return self.__class__.__name__ - - def __call__(self, *args, **kwargs): - return matplotlib_scraper(*args, format="svg", **kwargs) - # -- Project information ----------------------------------------------------- @@ -177,18 +166,16 @@ def __call__(self, *args, **kwargs): "examples_dirs": ["../examples"], # directory where to find plotting scripts "gallery_dirs": ["gallery"], # directory where to store generated plots "filename_pattern": "^((?!sgskip).)*$", # which files to execute, taken from matplotlib - # "subsection_order": ExampleTitleSortKey, - # "within_subsection_order": ExampleTitleSortKey, "backreferences_dir": "gen_modules/backreferences", # where function/class granular galleries are stored # Modules for which function/class level galleries are created "doc_module": "pyhdtoolkit", - # "image_scrapers": (matplotlib_svg_scraper(),), # scrape gallery as SVG + "image_scrapers": ("pyhdtoolkit.plotting.utils._matplotlib_svg_scraper",), # scrape gallery as SVG "image_srcset": ["2x"], # use srcset twice as dense for high-resolution images display "min_reported_time": 2, # minimum execution time to enable reporting "remove_config_comments": True, # remove config comments from the code "capture_repr": ("_repr_html_",), "compress_images": ("images", "thumbnails", "-o1"), - "only_warn_on_example_error": True, # keep the build going if an example fails, very important for doc workflow + "only_warn_on_example_error": True, # keep the build going if an example fails, important for doc workflow } # Config for the sphinx_panels extension diff --git a/pyhdtoolkit/plotting/utils.py b/pyhdtoolkit/plotting/utils.py index 30242d1f..7c040f77 100644 --- a/pyhdtoolkit/plotting/utils.py +++ b/pyhdtoolkit/plotting/utils.py @@ -488,3 +488,12 @@ def _determine_default_sbs_phase_ylabel(plane: str) -> str: beginning = r"\Delta " term = r"\phi_{x}" if plane.upper() == "X" else r"\phi_{y}" return r"$" + beginning + term + r"$" + +# ----- Sphinx Gallery Scraper ----- # + +# To use SVG outputs when scraping matplotlib figures for the sphinx-gallery, see: +# https://sphinx-gallery.github.io/stable/advanced.html#example-3-matplotlib-with-svg-format +def _matplotlib_svg_scraper(*args, **kwargs): + from sphinx_gallery.scrapers import matplotlib_scraper + kwargs.pop("format", None) + return matplotlib_scraper(*args, format="svg", **kwargs) \ No newline at end of file