fariza
fariza

Reputation: 644

passing options to a matplotlib backend in a clean way

For my personal use, several times I have modified the matplotlib gtk backend (also the tk and wx) , replacing the window with a notebook. This is because I use too many plots at the same time.

This time around I feel I can take the challenge to do a pull-request for my changes. But I want to do it as clean as possible. That is where I need advice (clean is the key).

I would like to place my class TabbedFigureManagerGTK3 inside backend_gtk3.py

The problem is that using

matplotlib.use('gtk3cairo')

or

matplotlib.use('gtk3agg')

Directs the specified backend (gtk3cairo or gtk3agg) to use backend_gtk3.FigureManagerGTK3

I do not want to replicate backend_gtk3agg.py and backend_gtk3cairo.py just to change the call to backend_gtk3.FigureManagerGTK3

I would like to implement a solution that allows the user to pass an option to the backend, and from there it choses the traditional FigureManagerGTK3 or my TabbedFigureManagerGTK3

I am looking for a recomendation on how to do it that has more chances to be accepted upstream (after pull-request and the whole shebang).

  1. Do I modify matplotlib.use to add something like **kwargs?

  2. Do I just recreate the whole backend_gtk3agg.py and backend_gtk3cairo.py (subclassing of course)

  3. Do I forget about trying to get this accepted and do it breaking the Coding guide

Thanks Federico

Upvotes: 0

Views: 101

Answers (1)

tacaswell
tacaswell

Reputation: 87356

This does sound like a nifty feature.

I would do it by modifying the existing manager and following how the PySide vs PyQt issue is handled (by using a secondary rcParams which controls which one the backend imports). In your case, I would add backend.gtk3.tabbed, or something similarly named, which controls how the manager behaves.

Write your modifications so that changes as little of the existing api as possible (breaking backwards compatibility is a no-go) and make it so a user that doesn't explicitly enable your changes won't even know they are there.

Also email the dev list, they are all pretty friendly. Or just open a PR, that is the most effective way to get feed back.

Upvotes: 1

Related Questions