Skip to content
  • Sponsor matplotlib/matplotlib

  • Notifications You must be signed in to change notification settings
  • Fork 7.9k

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

Closed
@mgeier

Description

@mgeier

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

Activity

WeatherGod

WeatherGod commented on Sep 14, 2018

@WeatherGod
Member
mgeier

mgeier commented on Sep 15, 2018

@mgeier
ContributorAuthor

@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

ImportanceOfBeingErnest commented on Sep 15, 2018

@ImportanceOfBeingErnest
Member

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

mgeier commented on Sep 18, 2018

@mgeier
ContributorAuthor

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Plot in JS Animation has larger margin than "normal" PNG plot · Issue #12115 · matplotlib/matplotlib