Bug summary
Very specific sequence of calls in ipython notebook results in backend being set to None, preventing figure from being displayed.
MatlotlibReproduceBug.ipynb
Code for reproduction
# Code is in attached notebook, copying cells here for awareness only, but NO guarantee that it will run or produce the error outside a notebook
%matplotlib ipympl
from matplotlib import pyplot as plt
import matplotlib as mpl
import numpy as np
print(mpl.get_backend())
# NEW CELL
fig, ax = plt.subplots(1, 1)
ax.plot(range(3))
fig.show()
# NEW CELL
np.random.randn(10000000)
# NEW CELL
fig, ax = plt.subplots(1, 1)
print(fig.canvas.manager)
print(mpl.get_backend())
ax.hist(range(3000))
ax.hist(range(300000))
print(fig.canvas.manager)
print(mpl.get_backend())
fig.show()
Actual outcome
Backend is correctly set for first figure. Second figure it is correctly set after creating figure, but after multiple calls to ax.hist it becomes None.
Expected outcome
I would expect a figure backend to remain unchanged unless explicitly set to something different by the user
Additional information
Tested this on a slightly older version of ipython/matplotlib. Upgraded everything and the bug still exists.
This is a bit messy to reproduce, and seems to be very dependent on the amount of data passed to ax.hist as well as calls made previously.
Specific pattern of using fig, ax = plt.subplot(...) and fig.show() is one I settled on previously due to other issues with the ipympl backend failing to display figures in some cases.
Operating system
NAME="Amazon Linux" VERSION="2023" ID="amzn" ID_LIKE="fedora" VERSION_ID="2023" PLATFORM_ID="platform:al2023" PRETTY_NAME="Amazon Linux 2023.6.20250317" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023" HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/" DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/" SUPPORT_URL="https://aws.amazon.com/premiumsupport/" BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023" VENDOR_NAME="AWS" VENDOR_URL="https://aws.amazon.com/" SUPPORT_END="2029-06-30"
Matplotlib Version
3.10.9
Matplotlib Backend
ipympl
Python version
Python 3.12.6
Jupyter version
7.5.3
Installation
pip
Bug summary
Very specific sequence of calls in ipython notebook results in backend being set to None, preventing figure from being displayed.
MatlotlibReproduceBug.ipynb
Code for reproduction
Actual outcome
Backend is correctly set for first figure. Second figure it is correctly set after creating figure, but after multiple calls to
ax.histit becomes None.Expected outcome
I would expect a figure backend to remain unchanged unless explicitly set to something different by the user
Additional information
Tested this on a slightly older version of ipython/matplotlib. Upgraded everything and the bug still exists.
This is a bit messy to reproduce, and seems to be very dependent on the amount of data passed to
ax.histas well as calls made previously.Specific pattern of using
fig, ax = plt.subplot(...)andfig.show()is one I settled on previously due to other issues with theipymplbackend failing to display figures in some cases.Operating system
NAME="Amazon Linux" VERSION="2023" ID="amzn" ID_LIKE="fedora" VERSION_ID="2023" PLATFORM_ID="platform:al2023" PRETTY_NAME="Amazon Linux 2023.6.20250317" ANSI_COLOR="0;33" CPE_NAME="cpe:2.3:o:amazon:amazon_linux:2023" HOME_URL="https://aws.amazon.com/linux/amazon-linux-2023/" DOCUMENTATION_URL="https://docs.aws.amazon.com/linux/" SUPPORT_URL="https://aws.amazon.com/premiumsupport/" BUG_REPORT_URL="https://github.com/amazonlinux/amazon-linux-2023" VENDOR_NAME="AWS" VENDOR_URL="https://aws.amazon.com/" SUPPORT_END="2029-06-30"
Matplotlib Version
3.10.9
Matplotlib Backend
ipympl
Python version
Python 3.12.6
Jupyter version
7.5.3
Installation
pip