[ENH]: Does pyplot need to call switch_backend · Issue #22739 · matplotlib/matplotlib · GitHub
Skip to content

[ENH]: Does pyplot need to call switch_backend #22739

Description

@hmaarrfk

Problem

It seems that simply importing pyplot can have serious effects on what backends are chosen, and how they interact with one and other.

In

They say that simply

from matplotlib import pyplot

can trigger setting the default backend.

This is somewhat frustrating for people who use interactive sessions.

Running the code

from matplotlib import pyplot
import matplotlib
matplotlib.use("WxAgg")

all at once will work in ipython (from the terminal). But running it one line at a time, won't.

This is somewhat strange.

Now that things like __getattr__ exist, would be possible to further delay setting the default backend?

The issue arises when you want to build an application, and other people's code might be imported before yours. You are then at their mercy to not set the backend (implicitly!) before you set yours.

Proposed solution

No solution. I'm sure there is some strange historic thing I'm missing.

Honestly, you created a great API with pyplot. People use it to get colormaps, and for all sorts of things.

XREF: DeepLabCut/DeepLabCut#1730

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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