CubeBrowser / cube-explorer

browser based exploration of iris cubes
BSD 3-Clause "New" or "Revised" License
8 stars 12 forks source link

Working with nbagg #47

Open philippjfr opened 8 years ago

philippjfr commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

philippjfr commented 8 years ago

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.