-
-
Notifications
You must be signed in to change notification settings - Fork 37
Do not enable default Matplotlib backend when checking what the backend is #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Collaborator
Author
|
The test image changes are on the |
Collaborator
Author
|
I've converted this to Draft as there are changes planned in Matplotlib that will make the fix different and better. |
Collaborator
Author
|
This is now ready. After this is merged I would like a new release. |
Member
|
Sorry I missed that ping me if this get delayed. |
Member
|
I've made you maintainer to unblock you a bit. |
This was referenced Mar 3, 2025
timhoffm
added a commit
to timhoffm/matplotlib
that referenced
this pull request
Jan 14, 2026
since 3.10 we have the official API `matplotlib.get_backend (auto_select=False)`. No problems have been reported and matplotlib-inline is using it https://github .com/ipython/matplotlib-inline/pull/38. Therefore, I remove the provisional status from the auto-select flag. Additionally, I deprecate the API rcParams._get('backend'), which the above is replacing. It seems that `rcParams._get("backend")` is not used anywhere publically, but let's still be defensive and deprecate. https://github.com/search?q=%2F%5C._get%5C%28%5B%22%27%5Dbackend%5B%22%27%5D%5C%29%2F+language%3APython+NOT+is%3Afork+NOT+path%3A**%2Fmatplotlib%2F**+NOT+path%3A**%2Fsite-packages**+NOT+path%3A**%2Fpyplot.py&type=code This is working towards matplotlib#26406. Follow-up to matplotlib#29039.
timhoffm
added a commit
to timhoffm/matplotlib
that referenced
this pull request
Jan 14, 2026
since 3.10 we have the official API `matplotlib.get_backend (auto_select=False)`. No problems have been reported and matplotlib-inline is using it https://github .com/ipython/matplotlib-inline/pull/38. Therefore, I remove the provisional status from the auto-select flag. Additionally, I deprecate the API rcParams._get('backend'), which the above is replacing. It seems that `rcParams._get("backend")` is not used anywhere publically, but let's still be defensive and deprecate. https://github.com/search?q=%2F%5C._get%5C%28%5B%22%27%5Dbackend%5B%22%27%5D%5C%29%2F+language%3APython+NOT+is%3Afork+NOT+path%3A**%2Fmatplotlib%2F**+NOT+path%3A**%2Fsite-packages**+NOT+path%3A**%2Fpyplot.py&type=code This is working towards matplotlib#26406. Follow-up to matplotlib#29039.
timhoffm
added a commit
to timhoffm/matplotlib
that referenced
this pull request
Jan 14, 2026
since 3.10 we have the official API `matplotlib.get_backend (auto_select=False)`. No problems have been reported and matplotlib-inline is using it https://github .com/ipython/matplotlib-inline/pull/38. Therefore, I remove the provisional status from the auto-select flag. Additionally, I deprecate the API rcParams._get('backend'), which the above is replacing. It seems that `rcParams._get("backend")` is not used anywhere publically, but let's still be defensive and deprecate. https://github.com/search?q=%2F%5C._get%5C%28%5B%22%27%5Dbackend%5B%22%27%5D%5C%29%2F+language%3APython+NOT+is%3Afork+NOT+path%3A**%2Fmatplotlib%2F**+NOT+path%3A**%2Fsite-packages**+NOT+path%3A**%2Fpyplot.py&type=code This is working towards matplotlib#26406. Follow-up to matplotlib#29039.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #37 and #25.
When importing
backend_inlinethe function_enable_matplotlib_integration()is automatically called and this checks what the current Matplotlib backend is. Previously callingmatplotlib.get_backend()if no backend was currently set would as a side-effect force it to be the default backend for that OS rather than leaving it unset. Changing it tomatplotlib.rcParams._get("backend")avoids the side-effect thus fixing the problem.Although
rcParams._getis a private function this is in fact the correct function to use as explained in the Matplotlib source code:https://github.com/matplotlib/matplotlib/blob/eb812a8e479d0bcf43a30232c31afec78963ed53/lib/matplotlib/__init__.py#L698-L713
To reproduce the original problem and confirm this PR fixes it use the following on the
mainbranch and this PR branch:~/.ipython/profile_default/ipython_kernel_config.pycontaining the single linec.InteractiveShellApp.matplotlib = 'inline'.jupyter laborjupyter qtconsoleand run the following code:import matplotlib.pyplot as plt; plt.plot([1,3,2])On
mainbranch this uses the wrong Matplotlib backend and on this PR branch it used the correctinlinebackend.I have manually tested other use cases of using Matplotlib in
ipythonandjupyterand it looks like this fix does not introduce any new problems.