Skip to content

Plot in JS Animation has larger margin than "normal" PNG plot #12115

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
mgeier opened this issue Sep 14, 2018 · 4 comments
Closed

Plot in JS Animation has larger margin than "normal" PNG plot #12115

mgeier opened this issue Sep 14, 2018 · 4 comments

Comments

@mgeier
Copy link
Contributor

mgeier commented Sep 14, 2018

Bug report

Bug summary

A few hours ago #12098 was merged, which left-aligns JS Animation plots and thereby fixes #11795.

This brought to light another little inconsistency between JS Animations and "normal" plots.
The PNG data in the JS Animation seems to have a larger white margin than normal plots.
Therefore, if I plot a normal plot and then a similar JS Animation, the plot in the JS Animation shows up a bit further right (because of the PNG margin).

Code for reproduction

I'm using the examples from https://splines.readthedocs.io/en/latest/bezier.html

Actual outcome

grafik

Expected outcome

Ideally, the PNG data in the JS Animation should have the same white margin as "normal" PNG plots.

Matplotlib version

  • Operating system: Debian Linux
  • Matplotlib version: master (848d9fc a.k.a. 3.0.0rc1.post275+g848d9fc56)
  • Matplotlib backend: module://ipykernel.pylab.backend_inline
  • Python version: 3.6.6
  • Jupyter version: JupyterLab 0.35.0a0
@WeatherGod
Copy link
Member

WeatherGod commented Sep 14, 2018 via email

@mgeier
Copy link
Contributor Author

mgeier commented Sep 15, 2018

@WeatherGod Indeed, I just checked with savefig('myplot.png') and it has the same white margin as the plots in the JS Animation. I wasn't aware that Jupyter manipulates the plots that it gets from Matplotlib.

Any ideas how I could make this consistent?

Manually remove the margins from Matplotlib plots?
Tell Jupyter to keep the margins?

@ImportanceOfBeingErnest
Copy link
Member

ImportanceOfBeingErnest commented Sep 15, 2018

I would also think that the way to make this consistent is rather to let jupyter not crop the figure.

You may use

%config InlineBackend.print_figure_kwargs = {'bbox_inches':None}

in a cell before the plot, or generally set this option in your IPython configuration. (I don't know about the differences between juypterlab and jupyter notebook though)

I think you may also use the ipympl backend instead of inline, in which case the figure should never be cropped. (Again, not sure about the differences between jupyterlab and notebook here)

@mgeier
Copy link
Contributor Author

mgeier commented Sep 18, 2018

Thanks @ImportanceOfBeingErnest, the suggested config setting for the InlineBackend works perfectly!

I still have to look into the ipympl backend some day ...

@mgeier mgeier closed this as completed Sep 18, 2018
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

3 participants