8000 Move overiding matplotlib RC to using a theme. · Issue #267 · ipython/ipykernel · GitHub
[go: up one dir, main page]

Skip to content

Move overiding matplotlib RC to using a theme. #267

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
Carreau opened this issue Sep 22, 2017 · 8 comments
Closed

Move overiding matplotlib RC to using a theme. #267

Carreau opened this issue Sep 22, 2017 · 8 comments

Comments

@Carreau
Copy link
Member
Carreau commented Sep 22, 2017

Right now we override matplotlib parameters when using inline:

rc = Dict({'figure.figsize': (6.0,4.0),
# play nicely with white background in the Qt and notebook frontend
'figure.facecolor': (1,1,1,0),
'figure.edgecolor': (1,1,1,0),
# 12pt labels get cutoff on 6x4 logplots, so use 10pt.
'font.size': 10,
# 72 dpi matches SVG/qtconsole
# this only affects PNG export, as SVG has no dpi setting
'figure.dpi': 72,
# 10pt still needs a little more room on the xlabel:
'figure.subplot.bottom' : .125
},
help="""Subset of matplotlib rcParams that should be different for the
inline backend."""
).tag(config=True)

We can do better now that matplotlib have styles; It wil have 2 advantages:

  1. let users changes the parameter we override (Weirdness with inline figure DPI settings in Jupyter Notebook matplotlib/matplotlib#9217 (comment))
  2. let users export figures using savefig with the same parameters than the inline plot.
@mgeier
Copy link
mgeier commented Nov 22, 2018

Is there any news on this?

Is there a way to have different presets (or "styles"?) for (kernels started by) the Qt Console and for (kernels started by) the Notebook?

I've also tried to get some information from the mailing list, but I didn't get a response:
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/jupyter/nSVmAsbaLnk

I've found out that the most meaningful figure.dpi setting for the Notebook is 96, while the current value of 72 seems best for Qt Console.

BTW, I also don't think it makes sense (anymore?) to change the default figure.figsize.
I'm not sure about the colors ...

I've made a notebook with a suggestion for an intermediate work-around: http://nbviewer.jupyter.org/github/mgeier/python-audio/blob/master/plotting/matplotlib-inline-defaults.ipynb

But it would be great if that could be fixed in IPython itself!

Here is an example that shows that plots using SVG and PNG with a setting of 96 DPI have about the same size:

https://nbsphinx.readthedocs.io/en/latest/code-cells.html#Plots

Here you can see the same thing for PDF and PNG plots when converted to LaTeX/PDF:

https://media.readthedocs.org/pdf/nbsphinx/latest/nbsphinx.pdf#subsubsection.4.3.4

@mangecoeur
Copy link

+1 to resolving this: at the moment you get the weird behavior that if you do %matplotlib inline and plt.rcParams['figure.dpi'] = 100 in the same cell, the manual dpi setting gets overridden, but if you do them in separate cells it doesn't. Which is bananas,

@dlukes
Copy link
Contributor
dlukes commented Aug 28, 2019

I'd love to help with this -- I teach Python to beginners using Jupyter Notebook / JupyterLab, and using matplotlib is always a stumbling block. Interactive plots are finicky to set up and use, and inline ones are too small by default, so they require fiddling with rcParams, which isn't beginner friendly either.

However, having downloaded the code and played around with it to figure out how it works, I'm not sure how switching to matplotlib styles is supposed to help, as claimed in OP:

We can do better now that matplotlib have styles; It wil have 2 advantages:

  1. let users changes the parameter we override (Weirdness with inline figure DPI settings in Jupyter Notebook matplotlib/matplotlib#9217 (comment))

If the hypothetical inline style sets figure.dpi to 72, then the effect will be exactly the same as the current code directly manipulating rcParams, the new value will just override any previously set value. Which means that setting a higher figure.dpi in matplotlibrc will still have no tangible effect, which is what matplotlib/matplotlib#9217 was originally complaining about.

Here's a quick demo showing that switching styles can still override previously set figure.dpi:

In [1]: import matplotlib as mpl                                                                                                                                                                                                               
In [2]: import matplotlib.pyplot as plt                                                                                                                                                                                                        
In [3]: mpl.rc("figure", dpi=150)                                                                                                                                                                                                              
In [4]: mpl.rcParams["figure.dpi"]                                                                                                                                                                                                             
Out[4]: 150.0
In [5]: plt.style.use("classic")
In [6]: mpl.rcParams["figure.dpi"]                                                                                                                                                                                                             
Out[6]: 80.0

So again, not sure how using styles to set inline rcParams would enable users to set a preferred figure.dpi via matplotlibrc. Or maybe I misunderstood the suggestion? If so, please clarify, I'd really like to help with this :)

@dlukes
Copy link
Contributor
dlukes commented Aug 28, 2019

Slightly unrelated, for future reference -- this is where the inline rcParams actually get loaded by IPython:

https://github.com/ipython/ipython/blob/8971c8e5f31d20768609e20f60870d627eb33bd0/IPython/core/pylabtools.py#L394-L395

@danieloliveira56
Copy link

I believe this commit to matplotlib-inline fixed this issue:
ipython/matplotlib-inline@a433a89

@fperez
Copy link
Member
fperez commented Sep 1, 2022

Thx for flagging that @danieloliveira56 - and FYI for all, that commit is now in the current 0.1.6 release of mpl-inline. So an update to that package might be enough to close this issue, I think.

@fperez
Copy link
Member
fperez commented Sep 4, 2022

This is old and I think solved, closing for now, please reopen if there's actually new actionable info.

@fperez fperez closed this as completed Sep 4, 2022
@dlukes
Copy link
Contributor
dlukes commented Sep 5, 2022

Fixed indeed, thank you very much!

image

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

6 participants
0