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: add user-facing no-output draw#19967

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

Closed
jklymak wants to merge2 commits intomasterfromenh-draw-no-output
Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletionsdoc/users/next_whats_new/fig_draw_no_output.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
Figure now has draw_no_output method
------------------------------------

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 that is
not user-facing, so a new method on `.Figure.draw_no_output` is provided.
9 changes: 8 additions & 1 deletionlib/matplotlib/figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,7 +26,7 @@
from matplotlib.artist import (
Artist, allow_rasterization, _finalize_rasterization)
from matplotlib.backend_bases import (
FigureCanvasBase, NonGuiException, MouseButton)
FigureCanvasBase, NonGuiException, MouseButton, _no_output_draw)
import matplotlib._api as _api
import matplotlib.cbook as cbook
import matplotlib.colorbar as cbar
Expand DownExpand Up@@ -2739,6 +2739,13 @@ def draw(self, renderer):

self.canvas.draw_event(renderer)

def draw_no_output(self):
"""
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)

def draw_artist(self, a):
"""
Draw `.Artist` *a* only.
Expand Down
5 changes: 2 additions & 3 deletionslib/matplotlib/tests/test_constrainedlayout.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -134,8 +134,7 @@ def test_constrained_layout7():
for gs in gsl:
fig.add_subplot(gs)
# need to trigger a draw to get warning
fig.draw(fig.canvas.get_renderer())

fig.draw_no_output()

@image_comparison(['constrained_layout8.png'])
def test_constrained_layout8():
Expand DownExpand Up@@ -327,7 +326,7 @@ def test_constrained_layout18():
ax2 = ax.twinx()
example_plot(ax)
example_plot(ax2, fontsize=24)
fig.canvas.draw()
fig.draw_no_output()
assert all(ax.get_position().extents == ax2.get_position().extents)


Expand Down
4 changes: 2 additions & 2 deletionslib/matplotlib/tests/test_figure.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -415,11 +415,11 @@ def test_autofmt_xdate(which):
@pytest.mark.style('default')
def test_change_dpi():
fig = plt.figure(figsize=(4, 4))
fig.canvas.draw()
fig.draw_no_output()
assert fig.canvas.renderer.height == 400
assert fig.canvas.renderer.width == 400
fig.dpi = 50
fig.canvas.draw()
fig.draw_no_output()
assert fig.canvas.renderer.height == 200
assert fig.canvas.renderer.width == 200

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp