Skip to content

Commit

Permalink
fix(docs): Add screenshot of cross-validation plot
Browse files Browse the repository at this point in the history
This is a quick fix to address #594.

In the end, I took a screenshot manually (by using the "Download plot as png" button of the Plotly widget) and displayed it with matplotlib.

Here are all the alternatives I considered, and what didn't work with them:
- Use SVG instead of PNG
	- For that, I'd need to use Plotly's `fig.write_image`, and the library that Plotly uses for this, Kaleido, is currently broken: plotly/Kaleido#210
- Export plotly figure to a file during the example and read it
	- For that I also need Plotly's `fig.write_image`
- Use Pillow for displaying, instead of matplotlib (which is not really made for that)
	- Only matplotlib is supported by sphinx-gallery, the library that renders the examples
  • Loading branch information
augustebaum committed Oct 29, 2024
1 parent 5c03161 commit 2d2e02a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions examples/plot_03_cross_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,18 @@
cv_results = cross_validate(lasso, X, y, cv=3, project=my_project_gs)

my_project_gs.get_item("cross_validation").plot

# %%
# Because Plotly graphs currently do not yet properly render in our docs engine due to `a bug in Plotly <https://github.com/plotly/plotly.py/issues/4828>`_,
# we also show a screenshot below.
# Alternatively, if you zoom in or out in your browser window, the Plotly graph should display properly again.

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

img = mpimg.imread("plot_03_cross_validate_plot_screenshot.png")
fig, ax = plt.subplots()
# fig.tight_layout(pad=0.01)
fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99)
ax.axis("off")
ax.imshow(img)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2d2e02a

Please sign in to comment.