Skip to content

[Bug]: matplotlib.interactive re-enabled by e.g. matshow() #30429

@Feuermurmel

Description

@Feuermurmel

Bug summary

The first call to matshow() re-enables interactive mode after it has been disabled by matplotlib.interactive(False). In a Jupyter notebook, this has the result of a figure not intended for display being shown in the output.

Code for reproduction

from matplotlib.artist import Artist
from matplotlib.pyplot import matshow
import matplotlib

# Deactivate interactive mode, so the figure below isn't rendered.
matplotlib.interactive(False)

print(matplotlib.is_interactive())
# Interactive mode get's re-enabled and figure is shown in output.
fig = matplotlib.pyplot.matshow([[1, 2], [3, 4]]).figure
print(matplotlib.is_interactive())

Actual outcome

The first print() will (correctly) show False. By the second print(), interactive mode has been re-enabled and True is printed. The figure saved to variable fig is show in the output.

Expected outcome

I would expect that matplotlib.interactive(False) would have a permanent effect. Interactive mode should stay turned off until re-enabled explicitly. The documentation of matplotlib.interactive() does not mention the behaviour I'm witnessing.

Additional information

Screen shot of the Jupyter notebook I'm using to demonstrate the issue:

Image

Operating system

macOS 14.7.7

Matplotlib Version

3.10.5

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

3.13.3

Jupyter version

7.4.5

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions