Give plot_directive output a max-width: 100%#19063
Give plot_directive output a max-width: 100%#19063timhoffm merged 1 commit intomatplotlib:masterfrom
max-width: 100%#19063Conversation
a801758 to
af7d34b
Compare
| raise self.error(str(e)) | ||
|
|
||
|
|
||
| def _copy_css_file(app, exc): |
There was a problem hiding this comment.
|
|
||
| {{ caption }} | ||
| {%- endif %} | ||
| {{ caption }} {# appropriate leading whitespace added beforehand #} |
There was a problem hiding this comment.
Stripping trailing whitespace here causes the extra whitespace from before the {% if it matches to be effectively prepended to the caption, causing a bug.
Stripping that earlier whitespace using {% - if doesn't work because then Jinja strips the newline separating the options from the content.
So I settled for this ugly solution which puts "{{ caption }}" up against the side.
The other option would be to remove the artificially-inserted leading whitespace from the first line of the "caption" (L758), but this would technically be changing API for users who already have made custom templates for use the with plot_directive.
| * | ||
| * Stylesheet controlling images created using the `plot` directive within | ||
| * Sphinx. | ||
| * |
There was a problem hiding this comment.
Sphinx includes some copyright/license stuff here, presumably since this file will be redistributed independently of the repository. I figure I don't mind my whole three lines of very advanced CSS becoming public domain upon distribution, but wanted to flag this in case there are legal ramifications I don't understand.
https://github.com/sphinx-doc/sphinx/blob/3.x/sphinx/templates/graphviz/graphviz.css#L7
| scenario: | ||
|
|
||
| .. plot:: | ||
| :caption: This caption applies to both plots. |
There was a problem hiding this comment.
This caption is repeated verbatim after each plot with my changes. This may not be what I would have expected to happen, but it is the existing behavior.
589925d to
aa5b193
Compare
aa5b193 to
25b5ead
Compare
PR Summary
Currently, non-sphinx-gallery plots in the documentation (for example, from a
.. plot::directive in a docstring) produce plots that do not scale with screen size. This means that on e.g. phones, the plots get chopped off, as seen here:Other Sphinx extensions (gallery, the inheritance diagram extension, etc) add their own custom CSS to make the images fit in the page. I copied the approach taken by
sphinx.ext.graphvizto get the following result:This became increasingly important for my GSOD work (e.g. #18544, where the API docs center around the inclusion of a "demo" figure showing the various options).
Edit: additionally, I had to fix an existing bug in
plot_directive.TEMPLATEthat caused Sphinx to warn (failing our tests) whenever there is both a caption and a custom class assigned to a figure.PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand 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).