Skip to content
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

Does %matplotlib notebook supposed to work? #76

Closed
mickaellalande opened this issue Dec 2, 2019 · 7 comments
Closed

Does %matplotlib notebook supposed to work? #76

mickaellalande opened this issue Dec 2, 2019 · 7 comments

Comments

@mickaellalande
Copy link
Contributor

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?

@mickaellalande mickaellalande changed the title Does %matplotlib notebook supposed to works? Does %matplotlib notebook supposed to work? Dec 2, 2019
@lukelbd lukelbd added the bug label Dec 2, 2019
@lukelbd
Copy link
Collaborator

lukelbd commented Dec 2, 2019

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.

@lukelbd
Copy link
Collaborator

lukelbd commented Dec 2, 2019

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

@lukelbd
Copy link
Collaborator

lukelbd commented Dec 2, 2019

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.

@lukelbd
Copy link
Collaborator

lukelbd commented Dec 3, 2019

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.

@lukelbd lukelbd closed this as completed Dec 3, 2019
@mickaellalande
Copy link
Contributor Author

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!

@bradyrx
Copy link
Collaborator

bradyrx commented Dec 3, 2019

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.

@lukelbd
Copy link
Collaborator

lukelbd commented Dec 4, 2019

@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
Projects
None yet
Development

No branches or pull requests

3 participants