Add show parameter to .pl.show() to control plt.show() behavior#537
Open
Add show parameter to .pl.show() to control plt.show() behavior#537
show parameter to .pl.show() to control plt.show() behavior#537Conversation
When running in scripts, `plt.show()` was called unconditionally, clearing the figure before users could save it with `plt.savefig()`. The new `show: bool | None = None` parameter gives users explicit control: - `None` (default): preserves current behavior (auto-detect via `sys.ps1`) - `True`: always call `plt.show()` - `False`: never call `plt.show()` Closes #494 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #537 +/- ##
==========================================
+ Coverage 83.74% 83.83% +0.08%
==========================================
Files 8 8
Lines 2553 2573 +20
==========================================
+ Hits 2138 2157 +19
- Misses 415 416 +1
🚀 New features to boost your workflow:
|
Member
|
I wonder if it closes #68 |
Also check matplotlib.is_interactive() when deciding whether to call plt.show() automatically. This covers IDE consoles (PyCharm, VS Code) and plt.ion() sessions that don't set sys.ps1. Closes #68 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
Author
|
I added another check for |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
show: bool | None = Noneparameter to.pl.show()so users can preventplt.show()from being called.plt.show()was called unconditionally (clearing the figure beforeplt.savefig()). Withshow=False, users can now save or further modify the figure.None) preserves current auto-detection behavior viasys.ps1.Closes #494
Before (script)
After
Behavior matrix
show=None(default)plt.show()plt.show()(same as before)Trueplt.show()plt.show()Falseplt.show()plt.show()Test plan
show=Falsepreventsplt.show(), saved image is not blankshow=Nonepreserves current behaviorshow=Truealways callsplt.show()show="yes") raisesTypeError🤖 Generated with Claude Code