Skip to content

Backport PR #23057 and #23106 #23113

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 4 additions & 6 deletions lib/matplotlib/pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,6 @@ def _get_backend_mod():
# will (re)import pyplot and then call switch_backend if we need to
# resolve the auto sentinel)
switch_backend(dict.__getitem__(rcParams, "backend"))
# Just to be safe. Interactive mode can be turned on without calling
# `plt.ion()` so register it again here. This is safe because multiple
# calls to `install_repl_displayhook` are no-ops and the registered
# function respects `mpl.is_interactive()` to determine if it should
# trigger a draw.
install_repl_displayhook()
return _backend_mod


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

# make sure the repl display hook is installed in case we become
# interactive
install_repl_displayhook()


def _warn_if_gui_out_of_main_thread():
if (_get_required_interactive_framework(_get_backend_mod())
Expand Down
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_pyplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,3 +335,17 @@ def test_fallback_position():
axtest = plt.axes([0.2, 0.2, 0.5, 0.5], position=[0.1, 0.1, 0.8, 0.8])
np.testing.assert_allclose(axtest.bbox.get_points(),
axref.bbox.get_points())


def test_pylab_integration():
IPython = pytest.importorskip("IPython")
mpl.testing.subprocess_run_helper(
IPython.start_ipython,
"--pylab",
"-c",
";".join((
"import matplotlib.pyplot as plt",
"assert plt._IP_REGISTERED is not None",
)),
timeout=60,
)