-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
plot directive: caption-option #18426
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
plot directive: caption-option #18426
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
Fix typo in sphinx test document. Co-authored-by: Elliott Sales de Andrade <[email protected]>
Fix typo in comment. Co-authored-by: Elliott Sales de Andrade <[email protected]>
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
pytest
passes).flake8
on changed files to check).flake8-docstrings
andpydocstyle<4
and 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).