Skip to content

[Bug]: plt.interactive(False) not preventing figure generation in jupyter unless %matplotlib inline is run first #23766

@nvaytet

Description

@nvaytet

Bug summary

Using plt.interactive(False) or plt.ioff() in Jupyter (Lab and classic notebook) does not seem to prevent automatic figure generation, unless the magic %matplotlib inline in run first, even though the inline backend is the default.

Code for reproduction

import matplotlib.pyplot as plt

plt.interactive(False)

fig, ax = plt.subplots()
a = 0

Actual outcome

Screenshot at 2022-08-29 14-25-08

Expected outcome

Explicitly running %matplotlib inline block figure creation:
Screenshot at 2022-08-29 14-26-48

Note that running %matplotlib inline has to be done BEFORE the first figure was created, if not it has no effect
Screenshot at 2022-08-29 14-28-29

Additional information

Using the widget backend works in the same way as inline: if called before any figures are created, figures are not automatically generated. If called after one figure was made, then plt.interactive(False) has no effect.

I also tried plt.ioff() instead of plt.interactive(False) but it gives the same results.

Operating system

Ubuntu 22.04

Matplotlib Version

3.5.2

Matplotlib Backend

inline (jupyterlab)

Python version

3.9

Jupyter version

3.4.2

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions