-
Notifications
You must be signed in to change notification settings - Fork 207
Images saved outside of pyplot are not picked up in the gallery #206
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
Comments
Indeed we relay on matplotlib to recognize the plotted figures and save them. We have an additional support for mayavi plots too. |
Here's a simple yt script that demonstrates the issue:
And here's another script that uses matplotlib (this is more or less what yt is doing internally)
This doesn't use the pyplot state machine at all, so the machinery in The approach I was planning to implement was to add a new configuration option to look for new |
In addition, what if someone wanted to make a |
In my mind the assumption of sphinx-gallery is that you run your example and you see figures pop up. The images in the rendered HTML should be the figures that pop up. |
yt purposely doesn't support interactive plotting (since it is commonly used in headless sessions). Rather than a plot popping up, it is saved to disk. From my perspective there is very little difference, especially when a script pretty clearly calls a function named "save". |
Out of interest, do you have a link to your project gallery, mostly to have an idea how it looks and the kind of examples you have? |
Not yet no, I'm still working on converting it. Our existing cookbook is here: |
Here's a gif showing what I have so far. This was generated using a version of sphinx-gallery with PR #208 applied: http://imgur.com/a/evidx |
This is related to a conversation I had with some of the pycortex people, who were in need of functionality to grab rst |
Just a note that #208 was closed because we didn't reach a consensus on whether this should be supported...are just deciding not to support this? Or is it worth somebody trying to finish up that PR? |
It would be really nice to support this. Not all graphics produced via python happen via pyplot. Encoding that assumption into sphinx-gallery means many libraries won't be able to use this project at all for their documentation. |
I also agree on being able to capture objects which are not matplotlib
images. How we might get to support that is still a matter of
discussion.
|
I think the most general approach would be to allow custom post-block image scrapers that take in which code block was run (maybe the leading comments, and the code?) and returns a list of image arrays (which SG will then save to the correct filenames). The simplest implementation of this could be a new class Another implementation could e.g. look for a VisPy canvas and take a screenshot of that (vispy/vispy#557). So I think it's pretty general, and allows people to extend SG beyond
where the |
(I'm volunteering to do this refactoring / new config var if people agree it makes sense) |
I think that the general is a great one: seems versatile and powerful. I
don't fully picture how it would be implemented.
|
Just curious, do you have a use case for this that is more precise that "people will want to do that at one point"? The thing I am a bit worried a bit is that the test coverage of sphinx-gallery is not that great so it is easy to break small things without realising. See #301 for example where we got bitten by this recently. About capturing saved files, this is what I had to say at the time: |
A related question: people increasingly ask me if sphinx-gallery will be able to handle HTML output / javascript viz libraries. There are more and more of these popping up (e.g. Altair, Bokeh, ipyvolume, ipywidgets, etc). Riffing off of @larsoner 's thoughts maybe it could be an |
That would be useful. How technically hard is it?
Sent from my phone. Please forgive typos and briefness.
…On Nov 8, 2017, 16:58, at 16:58, Chris Holdgraf ***@***.***> wrote:
A related question: people increasingly ask me if sphinx-gallery will
be able to handle HTML output / javascript viz libraries. There are
more and more of these popping up (e.g. Altair, Bokeh, ipyvolume,
ipywidgets, etc). Riffing off of @larsoner 's thoughts maybe it could
be an `HTMLImageScraper` or something?
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#206 (comment)
|
That is the big question :-) I am not sure off the top of my head but happy to brainstorm about it. Maybe that'd be worth its own separate issue though as it's a bit tangential to scraping files saved to disk? |
I was chatting w/ @jakevdp about this and he was interested in whether sphinx-gallery could be used w/ Altair. Maybe he has thoughts about how the outputs of these kinds of packages could be collected etc. |
Yes, in addition to the image-saving that this issue talks about, I'd like to use SG for VisPy as linked above: vispy/vispy#557
It doesn't sound too terrible (look for |
These could also even be turned into such plugins. Maybe a config var like:
```
plot_scrapers=['matplotlib', 'mayavi', LocalImageScraper, VisPyScraper]
```
I'm in the same line of thought. Building a list of capturers, and at
the same time we must have a plugin list for their representation, not
everything will be an image.
What I mean is that the user would want to extend SG to capture
arbitrary objects, which will then require an corresponding
representation in the RST file(including raw html if necessary). I have
a personal use case on video and bokeh plots.
I do see some major steps of refactoring the logic of SG to get here. I had
some early start in PR #160 and PR #239(both now obsolete and not merged)
- We still need to split the code execution into an independent
function. This will also simplify testing, and environment
isolation(we still do some nasty things cleaning modules, paths,
sys.argv) and be a step forward into multiprocessor builds.
- During execution of the code we should iterate all the available
capture functions. In Matplotlib and mayavi have access to the state
machine and we can capture the plots, save to disk(where SG chooses
naming, keeping track of name collisions between multiple capturers
will become harder). But on other objects the user might want/need to save
something to disk, and he will need some annotations in the code for
the capturer to recognize them. Everything that is captured, should
have somehow an unique representation, probably a file path.
- I'll repeat. How do we keep track of name collisions? And that was one
of my problems with PR#208, and that just having something that looks
for any image on disk might be too strong.
- After code is executed. We obtain some representation of the script by
blocks and its output by blocks. Probably a list of named tuples or a
dictionary, imitating the way a jupyter notebook has its
representation in a JSON structure.
- Little Nitpick, we might need a new strategy for generating
thumbnails if we have different objects captured.
- Then after code is executed. Building the RST file should be simple,
we'll need also new functions that generate the RST for the output
objects. Or maybe the capturer deals with this and is responsible for
returning the RST representation of the captured object(This is
probably simpler).
The thing I am a bit worried a bit is that the test coverage of
sphinx-gallery is not that great so it is easy to break small things
without realising. See #301 for example where we got bitten by this
recently.
Yes, this is something still to be improved. Maybe the refactoring helps
putting more tests in place.
|
This is a much more extensive proposal than what I have in mind. You're basically talking about changing SG from a run/extract-image/make-pretty library to run/extract-anything/make-pretty library. This clearly has more potential flexibility, but I suspect will be a lot more difficult to do and get right. Take a look at the (relative) simplicity of #313, which just does |
Closing this as the use case seems to be addressed by our new scraping API, feel free to reopen if I'm mistaken @ngoldbaum |
It looks like
sphinx-gallery
only picks up on an image if it is saved via pyplot. I'm working with a library that uses matplotlib for plotting but does not use pyplot, instead wrapping matplotlib's object oriented interface.It would be nice if in addition to intercepting images saved via pyplot there was also a scan for
.png
files in the directory that executes a given script. That way tools that generate images independent of matplotlib.pyplot will still be able to include images in a gallery.If this is an agreeable feature to add I'd be happy to take a shot at adding it. Also if my description isn't clear I can take a shot at making a minimal reproducible example.
The text was updated successfully, but these errors were encountered: