【问题标题】:Nesting a DynamicMap inside a DynamicMap is not supported不支持在 DynamicMap 中嵌套 DynamicMap
【发布时间】:2020-01-21 05:27:52
【问题描述】:

我为不同的时间序列绘制了不同的时间序列图,我制作了全息图,现在我正在绘制不同的纬度范围全息图然后我得到了异常:- 例外:不支持将 DynamicMap 嵌套在 DynamicMap 中。确保 DynamicMap 回调返回一个元素或 (Nd)Overlay。如果您应用了一个操作,请通过设置 dynamic=False 确保它不是动态的。

:DynamicMap [经纬度 :] :DynamicMap [日期和时间:] 我没有将情节作为 dynamicmap 的嵌套,

我试图在最后的最终情节中进行光栅化。它没有工作

    latlon_selPLot={f'lat:{k[0]} lon:{k[1]}':finalplot(k) for k in 
    [[(12,15),(80,85)],[(13,18),(81,95)]]}
    dd=df_div.opts(width=200, height=100)
    hmap11 = hv.HoloMap(latlon_selPLot, kdims='Lat and Lon :' )
    tiles*rasterize(hmap11)



 # Below is the code i am using , where i have to make change , 
 # so that i get holomap of lat_lon_selPlot when i select one 
 #lat_lon range then that particular area plot is shown .


 allplot={k.strftime("%Y-%m-%d %H:%M:%S"):plotthis(k)for k in 
 perdelta(strt, strt + timedelta(days=1), timedelta(hours=18))}
 allplot2={k.strftime("%Y-%m-%d %H:%M:%S"):plotsecond(k)for k in 
 perdelta(strt, strt + timedelta(days=1), timedelta(hours=18))}
 ....

 tiles = gv.tile_sources.Wikipedia
 hmap1 = hv.HoloMap(allplot, kdims='Date and Time :' )
 hmap2 = hv.HoloMap(allplot2, kdims='Date and Time :')

def finalplot(rng):

        finalplot=rasterize(hmap1.redim.range(Latitude=rng[0], 
        Longitude=rng[1])).options(**opts)*hmap2
        return finalplot

latlon_selPLot={f'lat:{k[0]} lon:{k[1]}':finalplot(k) for k in 
[[(12,15),(80,85)],[(13,18),(81,95)]]}
dd=df_div.opts(width=200, height=100)
hmap11 = hv.HoloMap(latlon_selPLot, kdims='Lat and Lon :' )
tiles*hmap11

我希望我的 lat_lon_selPlot 全息图也能工作。

【问题讨论】:

    标签: python-3.x plot holoviews dynamic-mapping


    【解决方案1】:

    rasterize 是一种所谓的动态操作,这意味着它返回一个 DynamicMap,只要其中一个流发生变化,它就会更新。在rasterize 的情况下,这允许它在您的绘图范围发生变化时进行更新。如果您不想要动态行为,则必须在 rasterize 调用中指定 dynamic=False,在您的情况下,这意味着您将拥有:

    def finalplot(rng):
        return rasterize(hmap1, x_range=rng[1], y_range=[0], dynamic=False).options(**opts)*hmap2
    

    也就是说,在这种情况下,您似乎仍会嵌套 HoloMaps。为了解决这个问题,你必须调用`.collat​​e`

    hmap11 = hv.HoloMap(latlon_selPLot, kdims='Lat and Lon :' ).collate()
    

    【讨论】:

    • 嗨,感谢您的快速回复,实际上我想要动态功能,因为我想在放大时动态更改数据。
    • 还有什么办法吗?要使用除全息图以外的下拉选项获取特定纬度范围的图?
    【解决方案2】:

    为了仅选择选定的经纬度范围,我正在执行 panel.select 的另一个过程。 但首先 select.value 被选中,当我更改另一个的 select.value 时,情节没有改变。 我在哪里做错了?我如何与 jlink 链接,我的 jlink 是否正确?

    tiles = gv.tile_sources.Wikipedia
    hmap1 = hv.HoloMap(allplot, kdims='Date and Time :' )
    hmap2 = hv.HoloMap(allplot2, kdims='Date and Time :')
    finalplot=tiles*rasterize(hmap1).options(**opts)*hmap2
    dd=df_div.opts(width=200, height=100)
    
    select = pn.widgets.Select(name='States', options=['TN','AP', 'Odisha'])
     latmin = [7, 13, 19]
     latmax = [14, 19, 22]
     longmin = [77, 79, 85]
     longmax = [83, 85, 88]
    if (select.value=='TN'):
        hhmap = rasterize(hmap1.redim.range(Latitude=(latmin[0],latmax[0]), Longitude= 
     (longmin[0], longmax[0])))
       select.jslink(finalplot, value='object')
        finalplot=tiles*hhmap*hmap2
    
     elif (select.value=='AP'):
          hhmap =rasterize(hmap1.redim.range(Latitude=(latmin[1],latmax[1]), Longitude= 
     (longmin[1], longmax[1]))).options(**opts)
       select.jslink(finalplot, value='object')
        finalplot=tiles*rasterize(hhmap)*hmap2
    
    else:
        hhmap = rasterize(hmap1.redim.range(Latitude=(latmin[2],latmax[2]), Longitude= 
       (longmin[2], longmax[2]))).options(**opts)
        select.jslink(finalplot, value='Odisha')
        finalplot=tiles*rasterize(hhmap)*hmap2
     # else:
     #     tiles*rasterize(hmap1).options(**opts)*hmap2
    
     finalplot=tiles*rasterize(hhmap).options(**opts)*hmap2
      finalplot=pn.Column(dd, finalplot, select).servable()    
      # finalplot=pn.Column(dd, finalplot).servable()
     finalplot
    

    如何链接另一个 select.value 选项,以便在 select.value 更改时出现不同的情节?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      • 2021-12-09
      • 1970-01-01
      相关资源
      最近更新 更多