简体   繁体   English

用Python绘制,Peicewise,Holoveiws,Bokeh,热图

[英]Plotting In Python, Peicewise, Holoveiws, Bokeh, Heatmaps

I need to discriminate against non physical data in my heatmaps. 我需要在热图中区分非物理数据。 I am using python(bokeh and holoviews). 我正在使用python(bokeh和holoviews)。

Example Code: 示例代码:

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

This code makes a heat map where the value of the function Z is mapped as a color for a region of x and y. 该代码生成一个热图,其中函数Z的值被映射为x和y区域的颜色。 So Z depends on x and y and for different values of x and y, Z will have different colors. 因此Z取决于x和y,并且对于x和y的不同值,Z将具有不同的颜色。

My problem: I need to discriminate against any situations where v1val < c . 我的问题:我需要区分v1val <c的任何情况。 The code I currently have plots all of the data but I need it to plot only the data for v1val > c and maybe assign a color like white or black to portion of the graph corresponding to v1val < c. 我目前拥有的代码可以绘制所有数据,但是我需要它仅绘制v1val> c的数据,并可能为对应于v1val <c的图形部分分配白色或黑色之类的颜色。 I also similarly need to white out or blackout any region where v2val < d. 同样,我还需要将v2val <d的任何区域涂黑或涂黑。 Essentially I want to black out or white out regions of my heatmap that correspond to non physical data ie when v1val < c and when v2val < d. 本质上,我想对与非物理数据相对应的热图区域进行涂黑或涂黑,即v1val <c和v2val <d时。

I have been trying different things but each time I have some idea I get an error like " The truth of a value of an array with more than one element is ambiguous. Use a.any() or a.all()" 我一直在尝试不同的方法,但是每次我有一个主意时,我都会收到一个错误,例如“具有多个元素的数组的值的真相不明确。请使用a.any()或a.all()”

Help with blacking out this non physical data would be much appreciated. 我们非常希望能帮助您屏蔽这些非物理数据。

You can see how to black out or white out regions of a heatmap in http://pyviz.org/tutorial/01_Workflow_Introduction.html : 您可以在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)

在此处输入图片说明

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

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