GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Do not enable default Matplotlib backend when checking what the backend is by ianthomas23 · Pull Request #38 · ipython/matplotlib-inline

Conversation

@ianthomas23

@ianthomas23 ianthomas23 commented Oct 17, 2024

Copy link
Copy Markdown
Collaborator

Fixes #37 and #25.

When importing backend_inline the function _enable_matplotlib_integration() is automatically called and this checks what the current Matplotlib backend is. Previously calling matplotlib.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 to matplotlib.rcParams._get("backend") avoids the side-effect thus fixing the problem.

Although rcParams._get is 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 main branch and this PR branch:

  1. Create file ~/.ipython/profile_default/ipython_kernel_config.py containing the single line c.InteractiveShellApp.matplotlib = 'inline'.
  2. Use either jupyter lab or jupyter qtconsole and run the following code: import matplotlib.pyplot as plt; plt.plot([1,3,2])

On main branch this uses the wrong Matplotlib backend and on this PR branch it used the correct inline backend.

I have manually tested other use cases of using Matplotlib in ipython and jupyter and it looks like this fix does not introduce any new problems.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ianthomas23 added 2 commits October 17, 2024 12:56
@ianthomas23
Do not enable default Matplotlib backend when checking what the backe…
3e22c27
…nd is
@ianthomas23
Update test images
29d915c
@ianthomas23

ianthomas23 commented Oct 17, 2024

Copy link
Copy Markdown
Collaborator Author

The test image changes are on the main branch rather than this PR; I have included them here rather than create a separate PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ianthomas23 ianthomas23 mentioned this pull request Oct 29, 2024
[MNT]: Improve backend selection API matplotlib/matplotlib#26406
Open
@ianthomas23
ianthomas23 marked this pull request as draft October 29, 2024 14:57
@ianthomas23

ianthomas23 commented Oct 29, 2024

Copy link
Copy Markdown
Collaborator Author

I've converted this to Draft as there are changes planned in Matplotlib that will make the fix different and better.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ianthomas23
Use improved syntax for matplotlib >= 3.10
8dad284
@ianthomas23
ianthomas23 marked this pull request as ready for review November 8, 2024 08:38
@ianthomas23

ianthomas23 commented Nov 8, 2024

Copy link
Copy Markdown
Collaborator Author

This is now ready. After this is merged I would like a new release.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Carreau
Carreau merged commit d7df790 into ipython:main Dec 10, 2024
@Carreau

Carreau commented Dec 10, 2024

Copy link
Copy Markdown
Member

Sorry I missed that ping me if this get delayed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Carreau

Carreau commented Dec 10, 2024

Copy link
Copy Markdown
Member

I've made you maintainer to unblock you a bit.

ianthomas23 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ianthomas23
ianthomas23 deleted the 37-no-auto-enable branch December 10, 2024 11:00
This was referenced Mar 3, 2025
Importing backend_inline triggers selection of QtAgg backend and tie-in of GUI event loop in IPython #25
Closed
Do not trigger backend auto-resolution #26
Closed
misc IPython 9 compatibility ipython/ipyparallel#931
Merged
@ksunden ksunden mentioned this pull request Jul 25, 2025
[Bug]: Using an ipython config of InteractiveShellApp.matplotlib='inline' fails on macos for matplotlib>3.9.0 matplotlib/matplotlib#28855
Closed
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jan 14, 2026
@timhoffm
MNT: Deprecate rcParams._get("backend")
f343d24
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 timhoffm mentioned this pull request Jan 14, 2026
MNT: Deprecate rcParams._get("backend") matplotlib/matplotlib#30963
Closed
timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Jan 14, 2026
@timhoffm
MNT: Deprecate rcParams._get("backend")
7e92025
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
@timhoffm
MNT: Deprecate rcParams._get("backend")
fc8fb3a
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

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Do not automatically resolve default Matplotlib backend

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@ianthomas23 @Carreau
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.