我需要区分我的热图中的非物理数据。我正在使用python(bokeh和holoviews)。
示例代码:
import numpy as np
import holoviews as hv
import warnings\
warnings.filterwarnings("ignore")
hv.extension('bokeh')
%opts Image [colorbar=True tools=['hover']
%opts Image (cmap='rainbow')
%output max_frames=3000
import Definitions as def #these are my equations
a = 2
b = .2
c = .3
d = .4
e = 0
f = 0
g = 0
h = 0
i = .2
j = 0
l = .2
m = 1
N = 100 # number of points
yval = np.linspace(0.1,1,N)
xval = np.linspace(0,5,N)
bounds = (0,.1,5,1) #this sets the bounds from .1 to 1 on y axis and 0 to 5 on x axis
xval,yval = np.meshgrid(xval, yval, indexing 'xy')
v1val = def.v1(yval,b,a,m,l,xval) #Calling my these definitions from a seperate file
v2val = def.v2(b,m,a)
Zlist = def.Z(a,v2val/d,v2val/c,h,e,i,j,xval,l,v1val,f,g)
plot = hv.Image(np.flipud(Zlist), label = "Z Heat Map" \
,bounds = bounds, vdims = hv.Dimension('Z', range=(0,1))).redimlabel(x = 'x', y = 'y')
plot
此代码生成一个热图,其中函数Z的值被映射为x和y区域的颜色。因此Z取决于x和y,并且对于x和y的不同值,Z将具有不同的颜色。
我的问题:我需要区分v1val 我一直在尝试不同的事情,但是每次我有一个主意时,我都会收到一个错误,例如“具有多个元素的数组的值的真相模棱两可。请使用a.any()或a.all() 非常希望帮助您屏蔽这些非物理数据。
答案 0 :(得分:0)
您可以在http://pyviz.org/tutorial/01_Workflow_Introduction.html中查看如何涂黑或涂白热图区域:
def nansum(a, **kwargs):
return np.nan if np.isnan(a).all() else np.nansum(a, **kwargs)
heatmap = df.hvplot.heatmap('Year', 'State', 'measles', reduce_function=nansum)