我不想在Bokeh后端显示矩阵的NaN值(由numpy.nan制成)。我尝试使用CustomJSHover,但无能为力,因为在一个简单的示例中,我也遇到了错误。
代码:
import numpy as np
import xarray as xr
import holoviews as hv
import geoviews as gv
hv.extension('bokeh','matplotlib')
import cartopy.crs as crs
from bokeh.models import HoverTool, CustomJSHover
x,y = np.mgrid[-50:51, -50:51] * 0.1
r = 0.5*np.sin(np.pi +3*x**2+y**2)+0.5
r[r<0.5]=np.nan
coords=np.arange(0,101)
custom=CustomJSHover(code="""
return value + " tot"
""")
tooltips=[
("value","@image{1.1}"), # GIVES RIGHT VALUE BUT WITH NaNs (0.1..0.6.. etc)
("value","@image{custom}") # GIVES some strange 0th, 1st, ... or NaN
]
hover = HoverTool(tooltips=tooltips, formatters={'image' : custom})
ds = xr.Dataset({'R': (['x', 'y'],r)},coords={'x': (['x'], coords),'y': (['y'], coords)})
ensemble = gv.Image(ds, kdims=['x', 'y'],vdims=[ 'R']).opts(tools=[hover])
ensemble
我希望NaN
的值不会以{2.1}的格式显示,而NaN
的值却是白色的,因此它们在悬停时根本不会显示。