Skip to content

Does %matplotlib notebook supposed to work? #76

Closed

Description

@mickaellalande

I am used to work with %matplotlib notebook in my notebooks to be able to navigate in the plots (zoom, etc.). But I realized that if I put %matplotlib notebook, the ProPlot plots do not show up and I need to come back to %matplotlib inline to make it work again. I am doing something wrong or is this supposed to work for ProPlot too? And if not, is this planned to be working in the future?

Activity

  1. changed the title [-]Does %matplotlib notebook supposed to works?[/-] [+]Does %matplotlib notebook supposed to work?[/+] on Dec 2, 2019
  2. lukelbd commented on Dec 2, 2019

    @lukelbd
    Collaborator

    This is a known issue (#62) -- the ProPlot tight layout algorithm sets the figure size automatically, so when you manually resize with interactive backends it gets instantly "snapped back" into place by the algorithm. In an upcoming patch (v0.1.4) I will have fig.set_size_inches() override the algorithm so that you can use interactive backends.

  3. lukelbd commented on Dec 2, 2019

    @lukelbd
    Collaborator

    For justification of why ProPlot sets the figure size automatically, see this page.

  4. lukelbd commented on Dec 2, 2019

    @lukelbd
    Collaborator

    Just tried out

    import proplot as plot
    %matplotlib notebook
    ref = 1
    f, axs = plot.subplots(ref=ref, nrows=3, ncols=3, aspect=1, axwidth=1.1, wratios=(3,2,2), share=0)
    axs[ref-1].format(title='reference axes', titleweight='bold', titleloc='uc', titlecolor='red9')
    axs[4].format(title='title\ntitle\ntitle', suptitle='Tight layout with simple grids')
    axs[1].format(ylabel='ylabel\nylabel\nylabel')
    axs[:4:2].format(xlabel='xlabel\nxlabel\nxlabel')
    axs.format(rowlabels=['Row 1', 'Row 2', 'Row 3'], collabels=['Column 1', 'Column 2', 'Column 3'])

    The notebook backend is a special case I think -- it internally tries to resize the figure, which triggers a redraw, which itself triggers a resize, ad infinitum. Looks terrible. This issue has high priority.

  5. lukelbd commented on Dec 3, 2019

    @lukelbd
    Collaborator

    I fixed this and released a new version on PyPi. Run

    pip install --upgrade proplot

    To use the notebook backend, you can use %matplotlib notebook, but that will bypass some useful things that ipython_matplotlib does to keep the style the same as the inline backend, so I recommend using

    import proplot as plot
    plot.rc.matplotlib = 'notebook'  # option 1
    # plot.ipython_matplotlib('notebook')  # option 2

    or adding the line matplotlib: notebook to the .proplotrc file that should have been automatically created in your home directory.

    Note that the tight layout algorithm and automatic figure rescaling must be automatically disabled for this backend... unfortunately I could not find any obvious workaround. The inline notebook backend is "special". Also note that the performance is not great when you have figure "super titles" or row/column labels on... I think this will be improved when #50 and #46 are done.

  6. mickaellalande commented on Dec 3, 2019

    @mickaellalande
    ContributorAuthor

    Thanks for the quick fix! I have just updated ProPlot and it works already, just cutting some side of the color bar in my example (I guess that's what you are mentioning):

    proplot_notebook

    import xarray as xr
    import proplot as plot
    plot.rc.matplotlib = 'notebook'
    
    da = xr.open_dataarray('snc_LImon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001.nc')
    
    f, axs = plot.subplots(proj='cyl', proj_kw={'lon_0':180}, axwidth=7)
    axs.format(
        geogridlinewidth=0.7, geogridcolor='gray8', geogridalpha=0.5, labels=True,
        coast=True, abc=True, abcstyle='a.'
    )
    m = axs[0].contourf(da, cmap='viridis')
    f.colorbar(m, label='%')

    File: snc_LImon_IPSL-CM6A-LR_historical_r1i1p1f1_gr_185001.zip

    PS: I have just discovered your package yesterday and I am impressed with it so far (more convenient and improving the existing matplolib/cartopy that I am used to)! Thanks for this great work!

  7. bradyrx commented on Dec 3, 2019

    @bradyrx
    Collaborator

    FYI @lukelbd , pip install proplot --upgrade won't work until you bump above v1.0. If users have proplot installed from the original repo, you had the version set to 1.0. So it sees the current pip version as being a lower version and thus won't upgrade automatically. Folks have to uninstall first then reinstall.

  8. lukelbd commented on Dec 4, 2019

    @lukelbd
    Collaborator

    @bradyrx This is now addressed in the README and install page.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions