Skip to content

Move backend mapping to Matplotlib #14311

Closed

Description

@ianthomas23

I wanted to draw your attention to matplotlib/matplotlib#27663, about moving the Matplotlib backend mappings out of IPython and into Matplotlib.

The primary use case it so support Matplotlib widgets (ipympl and matplotlib-inline) registering themselves as Matplotlib backends without requiring additional code in IPython and/or Matplotlib. The secondary use case is to support backends in IPython using Matplotlib's module://name.of.the.backend syntax, e.g.

%matplotlib module://mplcairo.backend

which one can already do using matplotlib.use(...) but not directly via the %matplotlib magic.

Whilst doing this it seems sensible to bring all of the backend registering and mapping together in one place, and that should be Matplotlib rather than IPython. I am not sure how easy (or even possible!) it will be to remove all the related hard-coded stuff in IPython, but I am willing to start and see how it goes.

Activity

  1. ivanov commented on Jan 30, 2024

    @ivanov
    Member

    Thanks for opening this up for awareness, @ianthomas23 ! This sounds like a good plan to me. I think the only modification we'd want is to keep the current hardcoded functionality to support older versions of Matplotlib that will not have the list_backends, as there are users who update some packages while pinning others, so we would not want to break them by assuming that when they get a newer IPython they will also get a recent Matplotlib.

  2. Carreau commented on Jan 31, 2024

    @Carreau
    Member

    +1, I have no issue hardcoding a matplotlib version check in IPython to either fall to the hardcoded path or assuming things get registered.

  3. ianthomas23 commented on Jan 31, 2024

    @ianthomas23
    CollaboratorAuthor

    Thanks both. Yes, I'll put in a check on matplotlib.__version__ and use the existing code for "old" Matplotlib.

    I have a concern about backend2gui. It won't be needed in future (apart from the above fallback) but I wonder if other downstream libraries might be using it such that it cannot just be removed. Maybe I need to add a shim so that use of backend2gui does the right thing by calling Matplotlib as necessary.

  4. Carreau commented on Jan 31, 2024

    @Carreau
    Member

    We can add a getattr to the module level that warns about pending deprecation on access.

  5. added a commit that references this issue on Apr 12, 2024
    e0d3e4c
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