-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Scraper function for sphinx-gallery, in plotly.io #1577
Conversation
scraper function + skeleton of sphinx doc with minimal gallery (two examples)
I'm struggling with installing the orca excutable on the CI |
Hi @emmanuelle, thanks this is very interesting. A couple of high-level thoughts. Rather than use monkey-patching it would be nice to handle this use-case with a custom renderer (Renderers were introduced in #1474). I'm also a little hesitant to introduce this logic into the plotly.py repo. Would it make sense to add this to sphinx gallery? |
So far, I've had all of the orca-dependent tests run in the |
Thanks for the comments @jonmmease ! Yes, a custom renderer would be nicer, I just read through #1474 and it seems well adapted. I initially proposed the scraper function to sphinx-gallery as a PR (sphinx-gallery/sphinx-gallery#493) but their policy is that each plotting library should maintain its own scraper, which kinda makes sense since there is a large number of plotting libraries. So if we want that other projects use plotly in their documentation when using sphinx-gallery (it was mentioned on the scikit-learn mailing-list that there is interest for this), I think we have to include it and maintain it... |
Thanks for the background @emmanuelle, having something in the plotly.py repo is fine in that case. Looking over the code, I think we could replace the Would it be possible to get away with only having a custom renderer and not the |
Thanks @jonmmease. The way sphing-gallery handles matplotlib examples is quite different, because it loops through the list of existing matplotlib figures with |
@jonmmease here is a version with a custom renderer. I can add more documentation and comments but first tell me whether this was what you had in mind. I also changed the examples so that now they call |
Oh and the tests failure seem to be due to something else than the tests added by this PR. |
plotly/io/_sg_scraper.py
Outdated
# This module defines an image scraper for sphinx-gallery | ||
# https://sphinx-gallery.github.io/ | ||
# which can be used by projects using plotly in their documentation. | ||
# This module monkey-patches plotly.offline.plot, so we do not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can now remove mention of monkey patching right?
Thanks for making the renderer update @emmanuelle, this looks nice. I left a couple of comments inline.
Sounds like it would be worth asking, as I'd expect this to be useful for other libraries as well. But it's not a lot of logic, so not a huge deal.
Yeah, this has been fixed on master so if you merge/rebase it should go away. Regarding the example in |
+ changed name of renderer sphinx -> sphinx-gallery, and changed wording of documentation
Hurray it's green! I think I addressed all your requests, I moved the sphinx files and gallery examples to plotly/plotly-sphinx-gallery. |
@jonmmease no hurry but since you're always very reactive, I just wanted to make sure that this hasn't fallen off your radar :-). |
haha, thanks for the ping. I haven't forgotten 🙂 I should be able to take a look tomorrow. BTW, are you fine leaving this for v4 or would you like to get it out into the word before that? |
v4 is fine, it should be in a month or so right? I'm used to slower development cycles so no pb :-). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great @emmanuelle, a couple of small comments/requests below but otherwise good to go. Thanks!
@jonmmease sorry to have let this idle for some time. I think the tests failure are not related to this PR. Shall I try to make a new PR to the |
Looks, good. Thanks! |
@emmanuelle, could you double check that your sphinx-gallery example works with the |
Yes it works! Thank you very much @jonmmease :-) |
* scraper function for sphinx-gallery, in plotly.io. scraper function + skeleton of sphinx doc with minimal gallery (two examples) * added psutil dep to tox.ini * python 2 compatibility * added orca dep to package.json for tests * removed typo * corrected bug * python 2 compatibility * added electron * try to configure orca * Moved test file so that it's tested by the orca build only. * use custom renderer for sphinx-gallery * removed sphinx files which are now in plotly-sphinx-gallery + changed name of renderer sphinx -> sphinx-gallery, and changed wording of documentation * Modified test with new renderer name * try to fix py2 compatibility * write_html instead of offline.plot * change import order
This PR proposes the addition of a scraper function in
plotly.io
, to be used by thesphinx-gallery
sphinx extension when a sphinx-based doc contains a gallery of examples. At the momentsphinx-gallery
has a scraper for matplotlib figures, but some open-source projects have expressed their interest in having figures with plotly.py instead.The PR also contains a minimal sphinx doc with two gallery examples (one for 2D, one for 3D). It's not necessary to merge this but I thought that having gallery examples in the code base could be useful.
Note that this PR does not require a sphinx-gallery dependency, because it will be sphinx-gallery which calls the scraper function and not the other way around.
One thing to decide is whether the function used in examples is
plot
oriplot
. Do most users work in notebooks and therefore useiplot
? The function is monkey-patched anyway so it's easy to change.