Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Give plot_directive output amax-width: 100%#19063

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

brunobeltran
Copy link
Contributor

@brunobeltranbrunobeltran commentedDec 4, 2020
edited
Loading

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:

overfull-example

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 bysphinx.ext.graphviz to get the following result:

fixed-overfull-example

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 inplot_directive.TEMPLATE that caused Sphinx to warn (failing our tests) whenever there is both a caption and a custom class assigned to a figure.

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • [N/A] New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • Conforms to Matplotlib style conventions (installflake8-docstrings and runflake8 --docstring-convention=all).
  • [N/A] New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • [N/A] API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

@@ -254,6 +254,13 @@ def run(self):
raise self.error(str(e))


def _copy_css_file(app, exc):
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.


{{ caption }}
{%- endif %}
{{ caption }} {# appropriate leading whitespace added beforehand #}
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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.
*
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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.
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

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.

@tacaswelltacaswell added this to thev3.4.0 milestoneJan 4, 2021
@timhoffmtimhoffm merged commitd45dcef intomatplotlib:masterJan 4, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.4.0
Development

Successfully merging this pull request may close these issues.

7 participants
@brunobeltran@tacaswell@dimpase@jklymak@jhpalmieri@timhoffm@QuLogic

[8]ページ先頭

©2009-2025 Movatter.jp