FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

matplotlibrc: is there a way to specify "backend" as either "Qt5Agg | Qt4Agg" (whatever is installed)? · Issue #8613 · matplotlib/matplotlib · GitHub

Repository navigation

matplotlibrc: is there a way to specify "backend" as either "Qt5Agg | Qt4Agg" (whatever is installed)? #8613

Closed

Description

I have loads of conda environments in parallel, some of which have Qt4 installed and some have Qt5. I used to have backend : Qt4Agg in my ~/.config/matplotlib/matplotlibrc, but nowadays this will get me errors when I'm in one of the Qt5-environments.

Ideally I would like to be able to specify backend : QtAgg and it should use either Qt5 or Qt4, whatever is available ad hoc.

I had a look at the backend selection stuff, but couldn't find how to do it. I'd propose to come up with a PR if somebody could give me a short tip, where to implement such a switch..

Activity

  1. tacaswell commented on May 12, 2017

    Member

    I think this is a very good idea.

    The places to fix this would be:

    • rcsetup.py to allow the new string for the backend
    • adding another epicycle to lib/matplotlib/backends/qt_compat.py to keep track of when it falls back and update the rcParams accordingly.
  2. added this to the milestone on May 12, 2017
  3. megies commented on May 12, 2017

    ContributorAuthor

    Alright, thanks for directions, I'll have a look. Appropriate base branch would be master, I guess?

  4. tacaswell commented on May 12, 2017

    Member

    Yeah, this would go in for 2.1, too big of a change for a patch release.

  5. megies commented on May 12, 2017

    ContributorAuthor

    So if I just add it in those two places mpl complains because it tries to lookup backend_qtagg.py.

    Should I put a dummy backend_qtagg.py in place that imports from either backend_qt5agg.py or backend_qt4agg.py or am I missing something?

  6. tacaswell commented on May 12, 2017

    Member

    Sorry, I missed a step in how the backend lookup works 😞 🐑 .

    Putting in a backend_qtagg.py which imports qt_compat (which should update the rcparams to be the Qt4 or Qt5) and then imports from the correct backend is a reasonable solution.

    The other option I see is to hack at pylab_setup in backendends/__init__.py to special-case the qt backeds, but that seems worse.

  7. anntzer commented on May 13, 2017

    Contributor

    What about letting backend just be a list of tentative backends that are tried one after the other?

  8. tacaswell commented on May 13, 2017

    Member

    @anntzer I like that idea better than what I suggested.

  9. megies commented on May 15, 2017

    ContributorAuthor

    Sounds good to me, I guess the process of trying one backend or the other doesn't hamper selecting a usable backend anymore? Back in the old days, selecting a backend sometimes used to be a one-shot operation.. e.g. when running some server scripts it was essential to select "AGG" (import matplotlib; matplotlib.use("AGG")) at the top of the file before any pyplot imports because switching was often not possible anymore once one backend was imported..?

  10. WeatherGod commented on May 15, 2017

    Member
  11. megies commented on May 15, 2017

    ContributorAuthor

    Thanks for the feedback @WeatherGod. This kind of backs my unease with specifying backend in RC as a list. Furthermore changing it to be a list instead of a string for one backend might have other side effects (backwards compatibility etc.).

    So maybe it would be least invasive to add a stub backend_qtagg.py that sets either Qt5 or Qt4..

    But I'll wait for more opinions for a while..

  12. anntzer commented on May 15, 2017

    Contributor

    One of the caveats I would have with the suggested approach is that there
    exists code in the wild (and possibly within mpl itself, I can't remember),
    that queries the list of imported modules so far and figures out which GUI
    toolkit to use based on what it finds in that list. If we have failed
    attempts to import a toolkit, the failed imports might leave behind partial
    imports in the tree, which may confuse some of those algorithms.

    I am almost certain such approaches are already broken -- one can e.g. manually import tkinter while the backend is Qt5Agg. The correct approach is (currently) to check the value of mpl.rcParams["backend"].

    I think a backcompatible way is to add a plural form rcParams["backends"] which specifies a list of backends, tries to set them up one at a time, and, whenever one succeeds, sets rcParams["backend"] accordingly. This requires no backend-switching as the algorithm will stop as soon as it successfully sets a backend.

  13. tacaswell commented on May 15, 2017

    Member

    I was thinking we accept either a list or a string for rcparams['backend']. The place where the backend lock-in happens is in pyplot due to the things returned from pylab_setup.

    The multiple backends should be tried in pylab_setup (basically go down the backend list until one of them imports cleanly), return the functions, and then you are locked in.

    [Edited to add the missing sentence]

  14. anntzer commented on May 15, 2017

    Contributor

    Actually that'd work too. If you want to sniff the actual backend, you read rcParams["backend"] and if it's a list, it means that matplotlib hasn't made its choice yet?

  15. WeatherGod commented on May 15, 2017

    Member
  16. WeatherGod commented on May 15, 2017

    Member
  17. anntzer commented on May 15, 2017

    Contributor

    the environment variable should just force the backend.

  18. anntzer commented on Jun 20, 2017

    Contributor

    Note that specifying the backends as a list would also solve issues such as #8518 ("the default backend is chosen at build time, and sometimes defaults to a non-interactive backend"): one can just default to e.g. ["macosx", "qt5agg", "qt4agg", ...] (basically copy-pasting the order used in setup.py for backend priority).

  19. modified the milestones: , on Jul 30, 2017
  20. anntzer commented on Sep 19, 2018

    Contributor

    Improved, but not closed, by #9795 (there's a fixed fallback list now).

  21. timhoffm commented on Jul 14, 2020

    Member

    Closing because Qt4 is deprecated since Matplotlib 3.3.

  22. QuLogic commented on Jul 14, 2020

    Member

    I'm not sure this is specifically about Qt4 vs Qt5. However, we have automatic backend selection now, so you could just leave out a backend from matplotlibrc and it would pick whichever one you have in your conda environment.

  23. removed this from the future releases milestone on Oct 6, 2022
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


      Back | FazBrowse Home | New Git URL