Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c5a24ff

Browse files
tacaswellanntzer
andauthored
Backport PR #23057 and #23106 (#23113)
* Backport PR #23057: FIX: ensure switching the backend installs repl hook Merge pull request #23057 from tacaswell/fix_pylab (cherry picked from commit b31c5ae) * Merge pull request #23106 from anntzer/tpi MNT: Reuse subprocess_run_helper in test_pylab_integration. (cherry picked from commit 51624b6) * TST: Adjust to state tracking on 3.5.x branch The implementation of tracking if the repl displayhook is installed changed on main. Adjust the backported test to work with the old way. Co-authored-by: Antony Lee <[email protected]>
1 parent 20cda21 commit c5a24ff

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,6 @@ def _get_backend_mod():
215215
# will (re)import pyplot and then call switch_backend if we need to
216216
# resolve the auto sentinel)
217217
switch_backend(dict.__getitem__(rcParams, "backend"))
218-
# Just to be safe. Interactive mode can be turned on without calling
219-
# `plt.ion()` so register it again here. This is safe because multiple
220-
# calls to `install_repl_displayhook` are no-ops and the registered
221-
# function respects `mpl.is_interactive()` to determine if it should
222-
# trigger a draw.
223-
install_repl_displayhook()
224218
return _backend_mod
225219

226220

@@ -311,6 +305,10 @@ class backend_mod(matplotlib.backend_bases._Backend):
311305
# See https://github.com/matplotlib/matplotlib/issues/6092
312306
matplotlib.backends.backend = newbackend
313307

308+
# make sure the repl display hook is installed in case we become
309+
# interactive
310+
install_repl_displayhook()
311+
314312

315313
def _warn_if_gui_out_of_main_thread():
316314
if (_get_required_interactive_framework(_get_backend_mod())

lib/matplotlib/tests/test_pyplot.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,3 +335,17 @@ def test_fallback_position():
335335
axtest = plt.axes([0.2, 0.2, 0.5, 0.5], position=[0.1, 0.1, 0.8, 0.8])
336336
np.testing.assert_allclose(axtest.bbox.get_points(),
337337
axref.bbox.get_points())
338+
339+
340+
def test_pylab_integration():
341+
IPython = pytest.importorskip("IPython")
342+
mpl.testing.subprocess_run_helper(
343+
IPython.start_ipython,
344+
"--pylab",
345+
"-c",
346+
";".join((
347+
"import matplotlib.pyplot as plt",
348+
"assert plt._IP_REGISTERED is not None",
349+
)),
350+
timeout=60,
351+
)

0 commit comments

Comments
 (0)