You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
referencing a plot_directive plot does not work #9346
Adding :caption: is easy.
In setup() add 'caption': directives.unchanged to the options. And in run() add if 'caption' in options: caption=options['caption'] before format_template().
Feel free to open a PR (preferably with a test -- sphinx has been having many backcompat issues in recent versions so we should try to make sure things stay in a working state...) :-)
Referencing plots is not explicitly mentioned in the docs, but since the plot_directive generates a figure, which can be labelled by putting a label in front of it, I would expect the plot to catch the label and the ref to be working. There is even code for moving
the reference from the "htmlonly" (or "latexonly") code to the actual figure node itself
The culprit is mark_plot_labels. It looks for tagnames html_only and latex_only, but they are actually named only. So it was never actually doing anything.
I modified the code such that it adds the :name: option to the figure in the template. I printed the result to console. The :name: is there as expected, but the ref does not work. If I paste the code, generated by the template engine, into the actual source, the ref is working.
Why does a label inside the only directive generated by the template engine not work?
I believe the root causation is how the only directive handles references, as pointed out at sphinx-doc/sphinx#2150.
If we add :name: along with other options, it will be rendered twice (one within only:: html and the other within only:: not html), which will cause the Duplicate explicit target name warning eventually.
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!
Activity
quantenschaum commentedon Oct 10, 2017
plotdirective should support the:name:option to add a named label.:caption:optionquantenschaum commentedon Oct 10, 2017
:numref:works with the following template inconf.pywhere theonlydirectives have been removed.quantenschaum commentedon Oct 10, 2017
Adding
:caption:is easy.In
setup()add'caption': directives.unchangedto theoptions. And inrun()addif 'caption' in options: caption=options['caption']beforeformat_template().anntzer commentedon Oct 10, 2017
Feel free to open a PR (preferably with a test -- sphinx has been having many backcompat issues in recent versions so we should try to make sure things stay in a working state...) :-)
quantenschaum commentedon Oct 10, 2017
When I try to add
'name'to theoptionsinsetup(), I getSo it seems, as if there was already a
nameoption, but supplying:name:does not work either.tacaswell commentedon Oct 11, 2017
Is this documented to work and does not or would you like this to work as described?
quantenschaum commentedon Oct 11, 2017
Referencing plots is not explicitly mentioned in the docs, but since the
plot_directivegenerates afigure, which can be labelled by putting a label in front of it, I would expect the plot to catch the label and the ref to be working. There is even code for movingbut it seems to fail.
quantenschaum commentedon Oct 11, 2017
The culprit is
mark_plot_labels. It looks for tagnameshtml_onlyandlatex_only, but they are actually namedonly. So it was never actually doing anything.After fixing this, it fails, because there is no
document.settings.env.labels. Where is it now?quantenschaum commentedon Oct 11, 2017
I modified the code such that it adds the
:name:option to the figure in the template. I printed theresultto console. The:name:is there as expected, but the ref does not work. If I paste the code, generated by the template engine, into the actual source, the ref is working.Why does a label inside the
onlydirective generated by the template engine not work?tushuhei commentedon Apr 28, 2021
I believe the root causation is how the
onlydirective handles references, as pointed out at sphinx-doc/sphinx#2150.If we add
:name:along with other options, it will be rendered twice (one withinonly:: htmland the other withinonly:: not html), which will cause theDuplicate explicit target namewarning eventually.eudoxos commentedon May 21, 2022
Anyone has a workaround for this, besides the hack in sfstoolbox/theory#5 ?
github-actions commentedon May 23, 2023
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!