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

ENH: draw no output#19968

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
tacaswell merged 3 commits intomatplotlib:masterfromjklymak:enh-draw-no-output
Apr 16, 2021
Merged

Conversation

jklymak
Copy link
Member

PR Summary

Make user-facingdraw_no_output to do the same thing asfig.canvas.draw

PR Checklist

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (runflake8 on changed files to check).
  • 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).
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymakjklymak added this to thev3.5.0 milestoneApr 15, 2021
@jklymakjklymak mentioned this pull requestApr 15, 2021
7 tasks
@jklymakjklymak requested a review fromtacaswellApril 15, 2021 20:21
Copy link
Contributor

@brunobeltranbrunobeltran left a comment
edited
Loading

Choose a reason for hiding this comment

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

I'm definitely +1 on this addition. It would be good to have a single, easy-to-understand, public place to point people that need this (as discussed in gitter, I get a large number of requests that boil down to people that need to make a figure, measure the size of some artists, then remake the figure with an "optimal" figure size).

Some thoughts:

draw has basically grown to do "mean" two things:

  1. crawl the artist tree
  2. actually do things involving the renderer

However a new user won't have the intuition that we do that (2) is something that historically we abuse "draw" to do, so maybe we should consider not even putting "draw" in the name? Or at least name the new method something that doesn't boil down to "draw but don't draw" maybe something likefinalize_artists, or something more semantically on the nose likefinalize_layout.

While there are many places this function should probably be called now (in both tests and docs) I think it's probably fine to do that piecemeal moving forward.

either the screen or a file. This is useful for determining the final
position of artists on the figure that require a draw like text.
This could be accomplished via ``fig.canvas.draw()`` but that is
not user-facing, so a new method on `.Figure.draw_no_output` is provided.
Copy link
Member

Choose a reason for hiding this comment

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

I don't agree thatfig.cavas.draw() is not user facing, we use it through out the examples and tutorials! I think the benefit here is thatdraw_on_output does not have any side effects out side of theFigure (where asdraw may update a GUI or in the case of (iirc) the SVG backend require a file to be open), is marginally faster (due to therenderer.draw_* methods being stubbed out to no-ops), and is "at the top level" on theFigure object.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Fair enough. All I meant by that is unless you are making a GUI or a backend you never need to know about the canvas.

I guess to suggest a heuristic to resolve the tension above: if we want users to know about and actively use an object in the normal course of things, we should guide them to it by removing top-level methods. In the case of "axis" it is arguably useful for the user to know about the axis objects and manipulate them directly, so it's probably worth removing some of the shadowing methods on "axes". For canvas I don't think we need any users to call methods on the canvas, unless of course they are making a GUI, so in this case it makes sense to bubble the method up.

I'll change the wording (definitely fewer side effects is another great reason to switch), look into moving the implementation to the public method.

We do use fig.canvas.draw a lot, so some follow up PRs would be great. Probably a good first issue activity.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

New text:

Rarely, the user will want to trigger a draw without making output to either the screen or a file.  This is useful for determining the final position of artists on the figure that require a draw like text.This could be accomplished via ``fig.canvas.draw()`` but has side effects,sometimes requires an open file, and is documented on an object most users do not need to access.  The `.Figure.draw_no_output` is provided to trigger a draw without pushing to the final output with fewer side effects.

tacaswell reacted with thumbs up emoji
Draw the figure with no output. Useful to get the final size of
artists that require a draw before their size is known (e.g. text).
"""
_no_output_draw(self)
Copy link
Member

Choose a reason for hiding this comment

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

If we are going to pull this up is it better to move the implementation here and replace our internal use of_no_output_draw withfig.draw_no_output()?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Done - lets see if I made any mistakes via CI

@jklymakjklymak marked this pull request as draftApril 16, 2021 19:37
@jklymakjklymak marked this pull request as ready for reviewApril 16, 2021 21:50
@tacaswelltacaswell merged commit11739ad intomatplotlib:masterApr 16, 2021
@jklymakjklymak deleted the enh-draw-no-output branchApril 16, 2021 21:58
@jklymakjklymak mentioned this pull requestApr 16, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@brunobeltranbrunobeltranbrunobeltran approved these changes

@tacaswelltacaswelltacaswell approved these changes

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

Successfully merging this pull request may close these issues.

3 participants
@jklymak@tacaswell@brunobeltran

[8]ページ先頭

©2009-2025 Movatter.jp