簡體   English   中英

如何在數據着色器熱圖中填充或插入稀疏數據空白空間(欠采樣)?

[英]How do you fill or intrerpolate sparse data empty space (undersampling) in a datashader heatmap?

在數據着色器中繪制一組數據時,如果 X 軸具有離散數字和欠采樣,則會在可以看到背景的列之間留下間隙。

我一直在嘗試通過設置更大的點大小或使用 dynspread 傳輸 function 來解決此問題。 不走運——很可能是我不知道應用這些的正確方法。

這是重現我的意思的示例代碼:

import pandas as pd
import numpy as np

import datashader as ds, colorcet
import holoviews as hv
from holoviews.operation.datashader import datashade
from holoviews import opts

# generate random dataset 0 - 10000
image = np.random.randn(250, 1024, 1024) + 10000
z, x, y = image.shape
print("z, x, y =", z, x, y)
    
# rearrange data to 'z' + 'value' array and convert to dataframe
arr = np.column_stack((np.repeat(np.arange(z),y*x), image.ravel()))
df = pd.DataFrame(arr, columns = ['X', 'Y'])

### Plot using in datashader
map = ds.Canvas(plot_width=800, plot_height=800)
agg = map.points(df, 'X', 'Y' )
pts = ds.tf.shade(agg, cmap=colorcet.fire)
ds.tf.set_background(pts, 'white')

當然,使用 bokeh 繪制相同的集合會顯示相同的內容。 更糟糕的是,如果你放大:

hv.extension("bokeh")
datashade(hv.Points(df), cmap=colorcet.fire).relabel('Value heatmap').opts(height=700, width=800)

在這種情況下,Datashader 按設計工作。 當將點渲染到柵格網格中時,它會向您顯示可用的實際點數據,直至像素網格可以顯示的限制。 如果一個像素中有多個數據點,則會匯總它們的計數或值。 如果某些像素中沒有數據,則不顯示數據。

聽起來您想要一種不同於數據陰影像素熱圖的 plot。 也許:

  • If your data represent regular samples from an underlying raster or quadmesh grid, use a datashaded hv.Image or hv.Quadmesh plot (or call canvas.raster or canvas.quadmesh directly), not an hv.Points or canvas.points plot
  • 如果您的數據表示來自基礎連續分布的任意位置的樣本,您可以在計算 Delaunay 或其他類型的三角剖分后使用數據陰影hv.TriMesh或 canvas.trimesh plot 在點之間填充,以便定義表面。
  • If your data represent arbitrarily located samples from a non-continuous distribution but you still want to approximate it with a continuous function, you can use a (non-datashaded) hv.Bivariate plot, which computes a smooth kernel density estimate that effectively "connects正如您所描述的那樣,這些點也可以消除局部密度差異。

這些選項都不能完全滿足您在這里的要求,但我認為 TriMesh 的行為最符合您的建議,同時在縮小的情況下仍然表現類似。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM