我正在寻找使用数据着色器将大型二维数据数组绘制为一系列点的帮助/建议,按幅度着色。我处理的数据存放在几个 2D HDF5 数据集中,时间索引存储在单独的数据集中。数据的第二个维度是空间维度(距离以 m 为单位),它是一个不均匀的阶梯系列浮点数。数据集通常非常大(~1000 x >1000000),所以我想处理核心数据框的构建,其中数据的 y 位置存储为列标题,x -location 是帧索引,我想将点颜色映射到数据值当我想从 dask 数据帧的数据着色器中绘制它时,我遇到的问题是,目前,我发现的唯一方法是展平数据框并创建两个相应的“x” 和 'y' 列来容纳索引和 y 位置。任何人都可以帮助我理解这种绘图是否可以在没有展平数据的步骤的情况下进行?
这是我迄今为止所做的一个例子:
import datashader as ds
import datashader.transfer_functions as tf
import numpy as np
import pandas as pd
import dask.dataframe as dd
import dask.array as da
import bokeh.plotting as bk
from bokeh.palettes import viridis
from datashader.bokeh_ext import InteractiveImage
bk.output_notebook()
# ------------------------
# This is a proxy for a function, which creates a delayed frame from
# a series of delayed pandas dataframes, each reading from a separate
# h5 dataset.
random_data = da.random.random((10000, 1000), chunks = (1000, 100))
frame = dd.from_array(random_data)
# ------------------------
# ------------------------
# Flatten the dataframe and create two additional arrays holding the x and y
# locations.
a = frame.compute() # I want to avoid this call on the whole dataframe
index = [a.index] * len(a.columns)
index = np.vstack(index).reshape((-1), order = 'F')
columns = [a.columns] * len(a.index)
columns = [item for sublist in columns for item in sublist]
data = a.values.flatten()
# ------------------------
# Now creating an in-memory frame for the data
plot_frame = pd.DataFrame(columns = ['x', 'y', 'z']) # Empty frame
plot_frame.x = index
plot_frame.y = columns[::-1] #Reverse column order to plot
plot_frame.z = data
# ------------------------
x_range = [a.index[0], a.index[-1]]
y_range = [a.columns[0], a.columns[-1]]
def create_image(x_range = x_range, y_range = y_range[::-1], w=500, h=500):
cvs = ds.Canvas(x_range=x_range, y_range=y_range, plot_height=h, plot_width=w)
agg = cvs.points(plot_frame, 'x', 'y', ds.mean('z'))
return tf.shade(agg, cmap = viridis(256))
def base_plot(tools='pan,wheel_zoom,reset, box_zoom, save'):
p = bk.figure(x_range = x_range, y_range = y_range, tools=tools,
plot_width=900, plot_height=500, outline_line_color=None,
min_border=0, min_border_left=0, min_border_right=0,
min_border_top=0, min_border_bottom=0, x_axis_type = 'datetime')
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
return p
p = base_plot()
InteractiveImage(p, create_image)
谁能推荐一种通过数据着色器管道更有效地处理此问题的方法?
提前致谢!