plot directive: caption-option#18426
plot directive: caption-option#18426QuLogic merged 6 commits intomatplotlib:masterfrom ulijh:plot-directive-caption-option
Conversation
This new option allows the user to add a caption to plots with the plotting code given in the directive's contents. * The option :caption: enforces a caption. * The option take precedence over the contents. * Tested and documented in the modul's doc string. * Note in next_whats_new
timhoffm
left a comment
There was a problem hiding this comment.
Modulo raising on ambiguity.
|
@tacaswell @timhoffm after I submitted I found out there was another PR #15304 doing the same thing. Could you have a look and check which one should be taken forward? Thanks a bunch. |
|
@ulijh, thanks for finding that. I would tend to say luck of the draw on this one. The original PR author probably needed to nag us a bit - if you are hung ho to see this through lets stick w/ this PR. |
|
I've just changed this to raise if the caption is given twice. Two things I could need some help with:
|
QuLogic
left a comment
There was a problem hiding this comment.
Some small typos.
I'm not sure we have any way to test failure cases for the Sphinx extension.
|
You can add proper context using To support both still, I think you'd have to add a matplotlib/lib/matplotlib/sphinxext/plot_directive.py Lines 245 to 248 in 855e3bb and then call self.error(str(e))
|
Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Fix typo in sphinx test document. Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Fix typo in comment. Co-authored-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
|
Hey guys, the context is added when the error is raised. From my point of view this seems OK to merge. Thanks to the reviewers! |
|
Thanks @ulijh! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again. |
|
Thanks for merging! :-) I'm very happy to have contributed (a little bit) to this great project! Thanks to all who invest their time in it! |
PR Summary
This PR adds an option :caption: to the plot directive. It partially solves #9346.
The new option enforces a caption when a single figure is generated.
The option take precedence over the contents when a separate file containing the code is used.
Tested and documented in the module's doc string.
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsandpydocstyle<4and runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).