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

Figure caption for python figures #5

Open
hagenw opened this issue Jan 15, 2016 · 7 comments
Open

Figure caption for python figures #5

hagenw opened this issue Jan 15, 2016 · 7 comments

Comments

@hagenw
Copy link
Member

hagenw commented Jan 15, 2016

For the figures created with .. plot::, there is in theory the possibility to gave them a caption, but this seems to work only for code included from files.

At the moment I solved the problem, by adding another figure:

.. plot::

    # some code here that produces a figure

.. _fig-some-figure:

.. figure:: img/placeholder.png
    :align: center

    Caption of the figure.

The placeholder.png file is a 1px large file as we have to include something.

Another disadvantage is that the provided permalink will only point to this small image (so, only to the caption) and the actual figure will be hidden and you have to scroll up.

@hagenw
Copy link
Member Author

hagenw commented Jan 15, 2016

We are using already numfig.
The problem is you cannot write the code in this way:

.. _fig-some-figure:

.. plot::

    # some code here that produces a figure

    Caption of the figure.

This will return a SyntaxError: invalid syntax error.

That is the reason why I added an additional .. figure:: command. If you look at the generated HTML it looks ok, but it generates two divs that are called figure, which is of course not so nice.

So, the problem is not, that it is not working altogether, but that it should work in a better way ;)

@mgeier
Copy link
Member

mgeier commented Jan 31, 2016

This might be interesting: jupyter/notebook#811

@mgeier
Copy link
Member

mgeier commented Mar 1, 2016

These might be interesting: sphinx-doc/sphinx#1858 and sphinx-doc/sphinx#2317.

@hagenw
Copy link
Member Author

hagenw commented Mar 1, 2016

OK, so hopefully it will work with sphinx 1.4

@hagenw
Copy link
Member Author

hagenw commented Nov 15, 2017

The proposed changes to sphinx are included now, but the problem is that also plot_directive.py of Matplotlib has to change, and this is not done yet: matplotlib/matplotlib#9346
So we have to stick with the workaround for a while, I guess.

Considering also sphinx-doc/sphinx#4080, there seems to be a general problem or maybe a not so elegant implementation of references in sphinx.

@hagenw
Copy link
Member Author

hagenw commented Dec 13, 2017

This is currently solved by the following workaround implemented by ef70c7b

.. plot::
    :nofigs:

    # some code here that produces a figure

.. plot::
    :context:
    :include-source: false
    :nofigs:

    save_fig('some-figure')

.. _fig-some-figure:

.. figure:: some-figure.*
    :align: center

    Caption of the figure.

Whereas save_fig() is a custom function using Matplotlib to save to png and pdf.

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

No branches or pull requests

2 participants