Skip to content

Commit

Permalink
docs: Reset figure DPI before each example (#1096)
Browse files Browse the repository at this point in the history
I followed the [sphinx-gallery
docs](https://sphinx-gallery.github.io/stable/advanced.html#resetting-before-each-example).

I tried to place `reset_mpl` in a different module in the hopes of
removing the warning about sphinx not being able to cache
`sphinx_gallery_conf`, but I couldn't manage to make the import work. I
noticed sklearn declares a function in `conf.py` as well so I don't
think it's too big a deal.

Closes #675
  • Loading branch information
augustebaum authored Jan 13, 2025
1 parent 947eee5 commit ad34c2d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/getting_started/plot_skore_product_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
# %%
import matplotlib.pyplot as plt

fig = plt.figure(layout="constrained", dpi=200)
fig = plt.figure(layout="constrained")
plt.plot(df["param_alpha"], df["rmse"])
plt.xscale("log")
plt.xlabel("Alpha hyperparameter")
Expand Down
2 changes: 1 addition & 1 deletion examples/getting_started/plot_working_with_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def my_func(x):

x = np.linspace(0, 2, 100)

fig, ax = plt.subplots(layout="constrained", dpi=200)
fig, ax = plt.subplots(layout="constrained")
ax.plot(x, x, label="linear")
ax.plot(x, x**2, label="quadratic")
ax.plot(x, x**3, label="cubic")
Expand Down
9 changes: 9 additions & 0 deletions sphinx/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
"../examples/model_evaluation/plot_cross_validate",
]


# https://sphinx-gallery.github.io/stable/advanced.html#resetting-before-each-example
def reset_mpl(gallery_conf, fname):
import matplotlib

matplotlib.rcParams["figure.dpi"] = 200


# sphinx_gallery options
sphinx_gallery_conf = {
"examples_dirs": "../examples", # path to example scripts
Expand All @@ -79,6 +87,7 @@
"backreferences_dir": "generated",
"doc_module": "skore",
"default_thumb_file": "./_static/images/[email protected]",
"reset_modules": (reset_mpl, "seaborn"),
}

# intersphinx configuration
Expand Down

0 comments on commit ad34c2d

Please sign in to comment.