我最近发现holoviews
并且该hv.Image
方法是plt.image
. 有一个非常酷的功能hv.HoloMap
,它允许人们输入一个函数并调整函数内的参数,以交互方式查看生成的二维数组。我尝试遵循一些启动HoloMap
对象和替代dynamicMap
对象的示例,但无法让它与我的数据一起使用。(http://holoviews.org/Tutorials/Showcase.html)
在我的真实数据集中,我将拥有 3D 数组,并且我想沿一个轴(z
在这种情况下)进行切片,在该轴上我可以交互地查看生成的切片。我在下面做了一个基本的numpy
例子xarray
:
如何使用我的(或)对象构建我的基本函数image_slice
(迭代z
维度)以查看我的 3D DataArray 的 2D 切片?hv.HoloMap
hv.dynamicMap
import xarray as xr
import numpy as np
import holoviews as hv; hv.notebook_extension()
#Building 2D Array (X & Y)
dist = np.linspace(-0.5,0.5,202) # Linear spatial sampling
XY,YX = np.meshgrid(dist, dist)
#Add along 3rd Dimension
Z_list = []
for i in range(10):
Z_list.append(xr.DataArray(XY*i,dims=["x","y"]))
#Concat list of 2D Arrays into a 3D Array
DA_3D = xr.concat(Z_list,dim="z")
# DA_3D.shape
# (10, 202, 202)
def image_slice(DA_var,k):
return(hv.Image(DA_var[k,:,:].values))
#http://holoviews.org/Tutorials/Showcase.html Interactive Exploration w/ Circular Wave example
keys = [(DA_3D,k) for k in range(10)] #Every combination
items = [(k, image_slice(*k)) for k in keys]
# visual_slice = hv.HoloMap(items)
# TypeError: unhashable type: 'DataArray
dmap = hv.DynamicMap(slice_image, kdims=[hv.Dimension('z_axis',range=(0, 10))])
# dmap
# TypeError: slice_image() missing 1 required positional argument: 'k'
# Which makes perfect sense because the first argument is the DataArray object but I don't know how to input that into this type of object since `hv.Dimension` requires a range
我使用Python 3.5.1
和Holoviews Version((1, 4, 3),