Skip to content
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

Support more _repr_*_ #1136

Open
oscargus opened this issue May 11, 2023 · 5 comments · May be fixed by #1138
Open

Support more _repr_*_ #1136

oscargus opened this issue May 11, 2023 · 5 comments · May be fixed by #1138

Comments

@oscargus
Copy link
Contributor

Context: I'm looking for a way to include GraphViz-(run-time)-generated in examples.

One way would be to enable capturing _repr_png_ and possibly _repr_svg_. Is it likely that you will accept a PR for this?

Slightly related: #1134 (as these may also be embedded rather than storing as separate files) xflr6/graphviz#199 (if graphviz includes _repr_html_ it would also enable it)

@drammock
Copy link
Contributor

Does it not work to use the .. graphviz:: directive in examples? I.e., in MNE-Python we have this:

.. graphviz:: ../_static/diagrams/git_setup.dot

which renders automatically as the "schematic of recommended setup" on this page https://mne.tools/dev/install/contributing.html#forking-the-mne-python-repository

... but I confess I don't think we've ever tried it in a SG-processed example.

@drammock
Copy link
Contributor

drammock commented May 11, 2023

I take that back. We have done it inside a SG-processed example:

https://github.com/mne-tools/mne-python/blob/468aae3daf975c0a81bf3a33a2037e078920bde6/tutorials/preprocessing/40_artifact_correction_ica.py#L151-L153

resulting image is at the end of this tutorial section

@larsoner
Copy link
Contributor

Nice! I'm guessing they'd rather have an automatic detection/embedding rather than having to add directives to their docs, though.

If Jupyter supports _repr_svg_ and _repr_png_ then we should add it as well. I don't think it would take many lines. @oscargus would you be up for trying to implement this?

@oscargus
Copy link
Contributor Author

@drammock one can for sure do that, but then it is either saving as a file or adding content of the dot-file to the rst. I've done that in https://da.gitlab-pages.liu.se/B-ASIC/examples/firstorderiirfilter.html#sphx-glr-examples-firstorderiirfilter-py and it works well, but doesn't benefit from any updates and is not as "fluent" as when showing plots. I've also used jupyter-sphinx with a good result: https://da.gitlab-pages.liu.se/B-ASIC/examples/connectmultiplesfgs.html but then the drawback is that I have to write a Python-docstring which contains embedded Python code, so it cannot easily be executed. (I may miss something here, I can admit, probably it is possible to write it as rst directly, rather than python -> rst -> python).

@larsoner I think Jupyter does. At least Spyder supports it (so qtconsole). Ipython supports a bunch of formats https://ipython.readthedocs.io/en/stable/config/integrating.html#rich-display

I'll give it a go, but not sure about the time plan (I'd like to do it soon, but should do other things). Nor if I can do it, but I agree from a quick look that it appears to not require that many lines. Just need to understand a bit more of the architecture.

@drammock
Copy link
Contributor

one can for sure do that, but then it is either saving as a file or adding content of the dot-file to the rst.

ah, OK, I somehow missed the point that the GraphViz source is being generated at runtime

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants