Skip to content

Fix showing and saving plot in check_swatinit - #807

Merged
larsevj merged 1 commit into
mainfrom
fix_showing_and_saving_plot_in_check_swatinit
Sep 5, 2025
Merged

Fix showing and saving plot in check_swatinit#807
larsevj merged 1 commit into
mainfrom
fix_showing_and_saving_plot_in_check_swatinit

Conversation

@larsevj

@larsevj larsevj commented Sep 4, 2025

Copy link
Copy Markdown
Collaborator

Resolves #795

From https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.show.html:

Notes

Saving figures to file and showing a window at the same time

If you want an image file as well as a user interface window, use [pyplot.savefig](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html#matplotlib.pyplot.savefig) 
before [pyplot.show](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.show.html#matplotlib.pyplot.show). 
At the end of (a blocking) show() the figure is closed and thus unregistered from pyplot. 
Calling [pyplot.savefig](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html#matplotlib.pyplot.savefig) afterwards would save a new and thus empty figure. 
This limitation of command order does not apply if the show is non-blocking or if you keep a reference to the figure and use [Figure.savefig](https://matplotlib.org/stable/api/_as_gen/matplotlib.figure.Figure.savefig.html#matplotlib.figure.Figure.savefig).

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.16%. Comparing base (c174caf) to head (6956132).

Files with missing lines Patch % Lines
src/subscript/check_swatinit/check_swatinit.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #807   +/-   ##
=======================================
  Coverage   85.16%   85.16%           
=======================================
  Files          49       49           
  Lines        7544     7544           
=======================================
  Hits         6425     6425           
  Misses       1119     1119           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@larsevj
larsevj marked this pull request as ready for review September 5, 2025 12:07
@larsevj
larsevj requested a review from a team September 5, 2025 12:08
@larsevj
larsevj merged commit a199b2e into main Sep 5, 2025
4 checks passed
@larsevj
larsevj deleted the fix_showing_and_saving_plot_in_check_swatinit branch September 5, 2025 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[check_swatinit] - Empty PNG Output When Plotting and Saving Figures

3 participants