ipython icon indicating copy to clipboard operation
ipython copied to clipboard

Move backend mapping to Matplotlib

Open ianthomas23 opened this issue 1 year ago • 4 comments
trafficstars

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.

ianthomas23 avatar Jan 30 '24 12:01 ianthomas23

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.

ivanov avatar Jan 30 '24 20:01 ivanov

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

Carreau avatar Jan 31 '24 09:01 Carreau

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.

ianthomas23 avatar Jan 31 '24 10:01 ianthomas23

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

Carreau avatar Jan 31 '24 10:01 Carreau