fix: pl.show() now displays in a plain Python REPL (#68)#745
Open
timtreis wants to merge 1 commit into
Open
Conversation
The show=None default keyed off `not hasattr(sys, "ps1")`, which suppressed plt.show() in any REPL. A plain Python console sets sys.ps1 but leaves matplotlib non-interactive (unlike Jupyter/IPython), so the figure never rendered. Decide purely on matplotlib.is_interactive(): interactive backends auto-render, scripts and plain REPLs need the explicit plt.show().
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #745 +/- ##
==========================================
- Coverage 79.59% 79.59% -0.01%
==========================================
Files 17 17
Lines 4641 4640 -1
Branches 1029 1029
==========================================
- Hits 3694 3693 -1
Misses 598 598
Partials 349 349
🚀 New features to boost your workflow:
|
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.
Problem
Fixes #68.
pl.show()did not display the figure in a plain Python REPL (PyCharm console, pasted REPL,python -i); users had to callplt.show()manually. Most recently re-reported here.Root cause
The
show=Nonedefault keyed offnot hasattr(sys, "ps1"). A plain Python REPL setssys.ps1but leaves matplotlib non-interactive (unlike Jupyter/IPython), soplt.show()was suppressed and nothing rendered.Fix
Drop the
sys.ps1check and decide purely onmatplotlib.is_interactive():plt.ion()) auto-render → noplt.show();plt.show().The new condition is strictly more permissive than the old one, so it never suppresses a
show()the old code emitted — it only adds the missing REPL case. Removed the now-unusedimport sys.Tests
Added
test_show_default_keys_off_is_interactive(parametrized over the interactive flag,sys.ps1set in both cases to prove the decision ignores it). Verified to fail on the old logic and pass on the fix.