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

Working with nbagg #47

Open
philippjfr opened this issue Apr 12, 2016 · 3 comments
Open

Working with nbagg #47

philippjfr opened this issue Apr 12, 2016 · 3 comments
Assignees

Comments

@philippjfr
Copy link
Contributor

In the last meeting we got a request to allow the user to work with the matplotlib nbagg backend to enable some of the interactive features that allows. Enabling nbagg in HoloViews is trivial and can be done simply by executing

%output backend='matplotlib:nbagg

This works fine for individual figures but because the nbagg backend applies some internal magic to compute the bounding box around all the figure artists, laying out multiple plots will often result in cut off axis labels, colorbars or even parts of the actual plot. I've investigated how to control the bounding box of the rendered figure in the nbagg backend but haven't been able to figure out a solution that actually works. If we do want to commit to using nbagg we'll need to discuss how the bounding box code in nbagg works with someone who is familiar with its internals.

@philippjfr
Copy link
Contributor Author

It seems as long as sufficient space is allocated at the edges of the plot and the size is correctly specified using nbagg works fine. HoloViews currently sets very tight bounds around the plot and nbagg ends up cutting too much of the plot off because it does not compute a tight bounding box before rendering. Setting a more conservative fig_bounds fixes a lot of these issues, so we could consider some way to adjust this automatically when nbagg is enabled.

There's still separate issues with aspects not being taken into account in Layouts but those are general issues to improve Layout support for which we already have extensive discussion in HoloViews.

@marqh marqh added ready and removed discussion labels Apr 18, 2016
@marqh
Copy link
Member

marqh commented Apr 19, 2016

consider this as a cube_browser set up option, to explicitly set the bounds to be nb_agg compliant

https://github.com/scitools/cube_browser

@marqh marqh self-assigned this Apr 19, 2016
@philippjfr
Copy link
Contributor Author

philippjfr commented Apr 19, 2016

As promised, here is a simple pure matplotlib example demonstrating that nbagg cuts things off:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook

plt.imshow(np.random.rand(10,10))
plt.colorbar()
ax = plt.gca()
ax.set_yticks([0, 3, 6, 9])
ax.set_yticklabels(['Long', 'Longer', 'Really Long', 'Really Really Long'])

and it gets even worse when reducing the margins using:

plt.gcf().subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)

The problem here is twofold, first of all there is no way that I'm aware of that allows requesting a tight bounding box. However even if the tight option was supported we would still want to supply an explicit bounding box so that the plot doesn't jump around when animating the frames.

@marqh marqh added in progress and removed ready labels Apr 20, 2016
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

2 participants