CubeBrowser / cube-explorer

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

Adding padding to plotting extents #33

Closed philippjfr closed 8 years ago

philippjfr commented 8 years ago

In HoloViews we compute the extents of each frame so the axes don't jump around from frame to frame. In #28 we add support for computing the extents in geographic Elements, however snapping to the exact data extent is problematic because it can obscure datapoints at the edges. This is even more crucial here because due to projection transforms you cannot assume that points with lower values will actually be lower on the projected axis. I propose we add support for padding the axes ranges in HoloViews.

Here's a simple example showing some basic padding for a plot of tube stations:

%%opts Points [xticks=5 yticks=5] {+axiswise}
points = hc.Points(tube_locations(), crs=crs.OSGB())(style=dict(color='r', s=100, marker=concentric_circle))
l, r = points.range(0)
b, t = points.range(1)
rangex, rangey = r-l, t-b
padding = 0.1
xpadding = rangex*padding
ypadding = rangey*padding
padded_extents = (l-xpadding, b-ypadding, r+xpadding, t+ypadding)

tiles = MapQuestOSM()
geotiles = hc.GeoTiles(tiles)(plot=dict(projection=tiles.crs, zoom=14))
geotiles * points + geotiles * points.clone(extents=padded_extents)

image

Note how the plot on left without padding is actually missing two points (at the top and bottom). We can go with something as simple as this or look into the heuristics matplotlib uses to pad axis ranges.