繁体   English   中英

四边形网格的全息视图和时间点 slider 不工作

[英]holoviews overaly of quadmesh and points with time slider not working

我试图在 hv.quadmesh 或 hv.image 之上覆盖 hv.points,这两个图都有时间维度。

import xarray as xr
import numpy as np
import pandas as pd
import holoviews as hv
hv.extension('bokeh')

#create data
np.random.seed(0)
temperature = 15 + 8 * np.random.randn(2, 2, 3)
precipitation = 10 * np.random.rand(2, 2, 3)
lon = [[-99.83, -99.32], [-99.79, -99.23]]
lat = [[42.25, 42.21], [42.63, 42.59]]
time = pd.date_range("2014-09-06", periods=3)
reference_time = pd.Timestamp("2014-09-05")

ds = xr.Dataset(
    data_vars=dict(
        temperature=(["x", "y", "time"], temperature),
        precipitation=(["x", "y", "time"], precipitation),
    ),
    coords=dict(
        lon=(["x", "y"], lon),
        lat=(["x", "y"], lat),
        time=time,
        reference_time=reference_time,
    ),
    attrs=dict(description="Weather related data."),
)
df = ds.temperature.to_dataframe().reset_index()


#create quadmesh plot
img = hv.Dataset(ds, ['lon', 'lat','time'],['temperature']).to(hv.QuadMesh,['lon', 'lat'],['temperature'])
img

图片

#create points plot
pnt = hv.Points(df,vdims=['temperature','time'], kdims=['lon','lat']).groupby('time').opts(color='temperature',cmap='turbo')
pnt

积分

图像和点的叠加只显示第一个 plot

img*pnt

图像*点

如果我从点 plot 中删除时间分量,我可以覆盖数据,但是 slider 不会随时间改变点值

img*hv.Points(df,vdims=['temperature','time'], kdims=['lon','lat']).opts(color='temperature',cmap='turbo')
[image*points with no time component][4]

谢谢您的帮助 !!

您的问题可能是由于转换为 dataframe 时时间对象的转换所致。

如果您通过以下方式手动尝试特定时间步长的 select 数据

dfSubset = df.where(df.time == ds.time[0]).dropna()

你会遇到一个错误。

根据我的经验,手动选择时间然后让 HoloViews 决定如何处理对象比分组然后通过.to()转换更好。

在您的情况下,这将是以下 3 行:

dsSubset = ds.where(ds.time == ds.time[0], drop=True)
dfSubset = df.where(df.time == df.time[0]).dropna()
hv.QuadMesh(dsSubset, ['lon', 'lat'] ) * hv.Points(dfSubset, ['lon','lat'], vdims=['temperature']).opts(color='temperature',cmap='plasma',colorbar=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM