Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make %matplotlib inline side effect free #10383

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

Closed
andim opened this issue Mar 7, 2017 · 10 comments
Closed

Make %matplotlib inline side effect free #10383

andim opened this issue Mar 7, 2017 · 10 comments

Comments

@andim
Copy link

andim commented Mar 7, 2017

Currently matplotlib inline sets a number of rc parameters. If you naively assume (as I did until recently) that it simply instructs the notebook to show plots inline, this can lead to bugs overwriting earlier defined rc settings. With the stylesheet support that matplotlib now has it might be better to separate the backend choice from loading a style sheet that looks nice in the notebook.

I raised the issue with Fernando on Twitter who encouraged me to propose PR. I am posting it here to solicit more feedback before moving forward.

@Carreau
Copy link
Member

Carreau commented Mar 8, 2017

Thanks for the issue.

I believe that we have another issue opened for that but I can't find it.
It ties into #10128 and #10255 and IIRC when we did go back and forth between changing the default and not and in both cases we got complaints so this is delicate.

In particular IIRC, the background color and default size if we don't change them are problematic.
But I believe its a good time to revisit these default.

@danielflanigan
Copy link

Please remove this behavior of overriding the settings in matplotlibrc. I understand that the (ugly) matplotlib defaults cause problems out of the box. However, I think the current behavior is extremely confusing for new users trying to change these defaults. For users who do not understand that %matplotlib inline is actually using an element of IPython (not matplotlib, not Jupyter), the path to solving this problem can be long. It took me quite a while the first time.

These default settings also seem to produce figures that are too small for modern monitors. A dpi of 72 times a 4.0" height produces a figure less than 300 pixels high, which is a quarter the height of a 1920 x 1200 monitor, but figures rendered with these defaults always seem significantly smaller than this.

I remember that in past years a line like
c.InlineBackend.rc = {'dpi': 72, etc.}appeared by default in one of the IPython config files. However, the current files created byipython profile create` make no mention of the inline backend. Searching the IPython help for "InlineBackend" (no space) returns no results. The top results of googling "c.InlineBackend.rc" are threads of people discussing this issue, e.g. here.

Possible compromise: overwrite rc settings only if the current matplotlibrc file is not in the config directory, using mpl.matplotlib_fname().startswith(mpl.get_configdir()) or similar. This would avoid problems for totally new users but would allow people to use matplotlibrc without having to learn about IPython config and insert a mysterious line into a file that does not exist in a fresh install.

Thanks for your time.

@fperez
Copy link
Member

fperez commented May 12, 2022

I completely agree that we should now revert this behavior in InlineBackend, esp. now that %matplotlib inline isn't explicitly required anymore in most cases. This results in super confusing behavior, as we only do the override when the first plot call is made. This leads to this type of situation:

image

So if a user wants to set some rcParams at the top of their file, they basically get overridden on first plot call. They have to go back and rerun that first cell again for their changes to take, for no comprehensible reason. I just spent a good 1/2 hour debugging this just now, even though I know I was one of the people who wrote that code years ago! :)

I think we should fall back to being as hands-off as possible now, and leave this configuration to mpl/the users. We made those choices for good reason early on when the notebook was very new (I actually think we started that with the Qt console), but now I think it causes more confusion than good. I think we should revert our overrides, and let folks make their fine-tuning as they wish, using standard mechanisms.

My vote would be to drop all our overrides here and leave things clean (note that code now lives in the separate matplotlib_inline package).

I ran some quick tests manually restoring the values we override, and things seem to work fine.

@Carreau
Copy link
Member

Carreau commented May 12, 2022

That's reasonable, we could provide a matplotlib notebook "style" for backward compat.

@fperez
Copy link
Member

fperez commented May 12, 2022

👍 I have a few min in between meetings, let me whip up a PR real quick :)

fperez added a commit to ipython/matplotlib-inline that referenced this issue May 12, 2022
@fperez
Copy link
Member

fperez commented May 12, 2022

Oops!!! Sorry - I was being lazy and used the in-browser code editor (.) and I didn't realized it pushed straight to master!! 😱

I quickly force-pushed to revert, and will make a PR next. Serves me well! 🤦

@fperez
Copy link
Member

fperez commented May 12, 2022

OK, now it's there, properly made. I have never touched that repo, so LMK if you'd like a bit of doc update too, happy to do it. gotta run now...

fperez added a commit to ipython/matplotlib-inline that referenced this issue May 20, 2022
@davidnero
Copy link

It's been a few months since this issue was fixed. If anyone here is also a maintainer on matplotlib-inline, could you publish an updated version?

@fperez
Copy link
Member

fperez commented Aug 13, 2022

@davidnero - see here where we're discussing indeed making a release. I'm volunteering for it b/c I need this before I start teaching!

Should happen soon.

@fperez
Copy link
Member

fperez commented Aug 13, 2022

I'm going to close this as the real issue is in the matplotlib-inline repo, fixed and only pending release of a new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants