在数据着色器中绘制一组数据时,如果 X 轴具有离散数字和欠采样,则会在可以看到背景的列之间留下间隙。
我一直试图通过尝试设置更大的点大小或使用 dynspread 传递函数来解决这个问题。不走运——很可能是我不知道应用这些的正确方法。
这是重现我的意思的示例代码:
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)