holoviz / geoviews

Simple, concise geographical visualization in Python
http://geoviews.org
BSD 3-Clause "New" or "Revised" License
584 stars 75 forks source link

LineContours does not work with bokeh backend #140

Closed scaine1 closed 5 years ago

scaine1 commented 6 years ago

This is more of a feature request than an issue. The following code (trivial example) works when using the matplotlib backend

import numpy as np
import xarray as xr
import holoviews as hv
import geoviews as gv
import geoviews.feature as gf
from cartopy import crs as ccrs

def create_data():
    """
    create fake example data
    """
    times = [np.datetime64('2018-02-22 00:00:00')]
    lons = np.arange(0, 360, 30)
    lats = np.arange(-90, 110, 20)

    dims = ('time', 'latitude', 'longitude')
    shape = (len(times), len(lats), len(lons))
    coords = {'latitude':lats, 'longitude':lons, 'time':times}

    pres = np.zeros(shape)
    pres[0, 3:5, 3:5] = 10
    pres_xr = xr.DataArray(pres, dims=dims, coords=coords)
    xr_ds = xr.Dataset({'time': times, 'latitude': lats,
        'longitude': lons,  'pres': (dims, pres)})
    return xr_ds

hv.extension('matplotlib')
renderer = hv.renderer('matplotlib')
#hv.extension('bokeh')
#renderer = hv.renderer('bokeh')
hv.output('size=200')

xr_ds = create_data()
vdims = ['pres']
kdims= ['time', 'latitude', 'longitude']
gv_ds = gv.Dataset(xr_ds, kdims=kdims, vdims=vdims, crs=ccrs.PlateCarree())

hv.Dimension.type_formatters[np.datetime64] = '%Y-%m-%d %H'

geo_dims = ['longitude', 'latitude']
img = (gv_ds.to(gv.LineContours, geo_dims) * gf.coastline)
renderer.save(img, 'test_linecontour')

However, when using the bokeh backend I get the following warning.

WARNING:root:OverlayPlot03549: No plotting class for LineContours type and bokeh backend found.

It looks like holoviews has an implementation of something similar to ContourLines i.e. http://holoviews.org/reference/elements/bokeh/Contours.html so I am hoping that it will be relatively easy to implement for someone who knows how the internals work. I have had a go myself and got lost.

philippjfr commented 5 years ago

This has now been implemented.