Datashader 图表#

折线图#

datashader.line(y, data_points=100, add_interaction=True, pixel_shade_type='linear', color=None, step_size=None, step_size_type=<class 'int'>, title='', timeout=100, unselected_alpha=0.2)#
参数:
x: str

GPU 数据帧中的 x 轴列名

y: str

GPU 数据帧中的 y 轴列名

x_range: tuple, 默认值 (gpu_dataframe[x].min(), gpu_dataframe[x].max())

要显示的地理散点图的 (min, max) x 维度

y_range: tuple, 默认值 (gpu_dataframe[y].min(), gpu_dataframe[y].max())

要显示的地理散点图的 (min, max) x 维度

add_interaction: {True, False}, 默认值 True
pixel_shade_type: str, 默认值 ‘linear’

datashader.transfer_functions.shade() 函数中的 “how” 参数。可用选项:eq_hist, linear, log, cbrt

color: str, 默认值 #8735fb
step_size: int, 默认值 None

用于图表下方的 range_slider

step_size_type: type, 默认值 int

用于图表下方的 range_slider

title: str,

图表标题

timeout: int(毫秒),默认值 100

确定回调处理新事件的超时时间,而无需等待上一个事件报告完成。对于运行时间很长的回调以及缩放感觉卡顿时,请增加此值。

unselected_alpha: float [0, 1],默认值 0.2

如果为 True,则使用相同的颜色调色板但透明(alpha=0.2)显示未选定的数据。

返回:
类型为 cudashader 散点图

cuxfilter.charts.datashader.custom_extensions.InteractiveDatashaderLine

示例#

from cuxfilter import DataFrame
from cuxfilter.charts.datashader import line
import numpy as np
import cudf
import random
import cuxfilter

n = 100000                           # Number of points
start = 1456297053                   # Start time
end = start + 60 * 60 * 24

cux_df = DataFrame.from_dataframe(cudf.DataFrame({'x': np.linspace(start, end, n), 'y':np.random.normal(0, 0.3, size=n).cumsum() + 50}))
line_chart_1 = line(x='x', y='y', unselected_alpha=0.2)

d = cux_df.dashboard([line_chart_1])
line_chart_1.view()

散点图#

datashader.scatter(y, x_range=None, y_range=None, add_interaction=True, color_palette=None, aggregate_col=None, aggregate_fn='count', point_size=15, point_shape='circle', pixel_shade_type='eq_hist', pixel_density=0.5, pixel_spread='dynspread', tile_provider=None, title='', timeout=100, legend=True, legend_position='top_right', unselected_alpha=0.2, xaxis=False, yaxis=False)#
参数:
x: str

GPU 数据帧中的 x 轴列名

y: str, 默认值 None

GPU 数据帧中的 y 轴列名

x_range: tuple, 默认值 (gpu_dataframe[x].min(), gpu_dataframe[x].max())

要显示的地理散点图的 (min, max) x 维度

y_range: tuple, 默认值 (gpu_dataframe[y].min(), gpu_dataframe[y].max())

要显示的地理散点图的 (min, max) x 维度

add_interaction: {True, False}, 默认值 True
color_palette: bokeh.palettes 或 hex_color_codes 列表/元组,

或颜色名称列表/元组,默认值 bokeh.palettes.Virisdis10

aggregate_col: str, 默认值 None

GPU 数据帧中的列,将在其上运行 aggregate_fn,如果为 None,则在 y 列上运行 aggregate_fn

aggregate_fn: {‘count’, ‘mean’, ‘max’, ‘min’},默认值 ‘count’
point_size: int, 默认值 1

散点图中的点大小。

point_shape: str, 默认值 ‘circle’

可用选项:circle, square, rect_vertical, rect_horizontal。

pixel_shade_type: str, 默认值 ‘eq_hist’

datashader.transfer_functions.shade() 函数中的 “how” 参数。可用选项:eq_hist, linear, log, cbrt

pixel_density: float, 默认值 0.5

[0, 1] 范围内的调整参数,值越高,散点图越密集。

pixel_spread: str, 默认值 ‘dynspread’

dynspread:根据图像密度动态扩展图像中的像素。 spread:扩展图像中的像素。

tile_provider: str, 默认值 None

底层地图类型。参见 https://holoviews.org/reference/elements/bokeh/Tiles.html

title: str,

图表标题

timeout: int(毫秒),默认值 100

确定回调处理新事件的超时时间,而无需等待上一个事件报告完成。对于运行时间很长的回调以及缩放感觉卡顿时,请增加此值。

legend: bool, 默认值 True

如果为 True,则添加基于 Bokeh.models.LinearColorMapper 的图例,注意:图例当前仅适用于 pixel_shade_type=’linear’/’log’

legend_position: str, 默认值 top_right

图表上图例的位置。有效位置有:right, left, bottom, top, top_right, top_left,

bottom_left, bottom_right

unselected_alpha: float [0, 1],默认值 0.2

如果为 True,则使用相同的颜色调色板但透明(alpha=0.2)显示未选定的数据。

xaxis: bool, 默认值 False

如果为 True,则显示带标签的 x 轴

yaxis: bool, 默认值 False

如果为 True,则显示带标签的 y 轴

返回:
类型为 cudashader 散点图

cuxfilter.charts.datashader.custom_extensions.InteractiveDatashaderPoints

示例#

from cuxfilter import DataFrame
from cuxfilter.charts import scatter
import cudf
import random

cux_df = DataFrame.from_dataframe(cudf.DataFrame({'x': [float(random.randrange(-8239000,-8229000)) for i in range(10000)], 'y':[float(random.randrange(4960000, 4980000)) for i in range(10000)]}))
# setting pixel_shade_type='linear' to display legend (currently supports only log/linear)
scatter_chart = scatter(x='x',y='y', pixel_shade_type="linear", unselected_alpha=0.2)

d = cux_df.dashboard([scatter_chart])
scatter_chart.view()

堆叠折线图#

datashader.stacked_lines(y, data_points=100, add_interaction=True, colors=[], step_size=None, step_size_type=<class 'int'>, title='', timeout=100, legend=True, legend_position='top_right', unselected_alpha=0.2)#

堆叠折线图

参数:
x: str

GPU 数据帧中的 x 轴列名

y: list

用于堆叠折线图的 GPU 数据帧中的 y 轴列名

add_interaction: {True, False}, 默认值 True
colors: list, 默认值 [#8735fb, #8735fb, ….]
step_size: int, 默认值 None

用于图表下方的 range_slider

step_size_type: type, 默认值 int

用于图表下方的 range_slider

title: str,

图表标题

timeout: int(毫秒),默认值 100

确定回调处理新事件的超时时间,而无需等待上一个事件报告完成。对于运行时间很长的回调以及缩放感觉卡顿时,请增加此值。

legend: bool, 默认值 True

如果为 True,则添加基于 Bokeh.models.LinearColorMapper 的图例,注意:图例当前仅适用于 pixel_shade_type=’linear’/’log’

legend_position: str, 默认值 top_right

图表上图例的位置。有效位置有:right, left, bottom, top, top_right, top_left,

bottom_left, bottom_right

unselected_alpha: float [0, 1],默认值 0.2

如果为 True,则使用相同的颜色调色板但透明(alpha=0.2)显示未选定的数据。

返回:
类型为 cudashader 堆叠折线图

cuxfilter.charts.datashader.custom_extensions.InteractiveDatashaderMultiLine

示例#

from cuxfilter.sampledata import signals_data
from cuxfilter import DataFrame
from cuxfilter.charts import stacked_lines

cux_df = DataFrame.from_dataframe(signals_data)

stacked_lines_chart = stacked_lines(x='Time', y=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'x', 'y', 'z'],
                                                    colors = ["red", "grey", "black", "purple", "pink",
                                                            "yellow", "brown", "green", "orange", "blue"],
                                                    unselected_alpha=0.2
                                                    )

d = cux_df.dashboard([stacked_lines_chart])

stacked_lines_chart.view()

热力图#

datashader.heatmap(y, x_range=None, y_range=None, add_interaction=True, color_palette=None, aggregate_col=None, aggregate_fn='mean', point_size=15, point_shape='rect_vertical', title='', timeout=100, legend=True, legend_position='top_right', unselected_alpha=0.2, xaxis=True, yaxis=True)#

使用默认 datashader.scatter 图并稍作修改的热力图。添加此项是为了提供更好的默认值。理论上,可以直接使用 scatter 生成相同的图。

参数:
x: str

GPU 数据帧中的 x 轴列名

y: str, 默认值 None

GPU 数据帧中的 y 轴列名

x_range: tuple, 默认值 (gpu_dataframe[x].min(), gpu_dataframe[x].max())

要显示的地理散点图的 (min, max) x 维度

y_range: tuple, 默认值 (gpu_dataframe[y].min(), gpu_dataframe[y].max())

要显示的地理散点图的 (min, max) x 维度

add_interaction: {True, False}, 默认值 True
color_palette: bokeh.palettes 或 hex_color_codes 列表/元组,

或颜色名称列表/元组,默认值 bokeh.palettes.Virisdis10

aggregate_col: str, 默认值 None

GPU 数据帧中的列,将在其上运行 aggregate_fn,如果为 None,则在 y 列上运行 aggregate_fn

aggregate_fn: {‘count’, ‘mean’, ‘max’, ‘min’},默认值 ‘count’
point_size: int, 默认值 1

散点图中的点大小。

point_shape: str, 默认值 ‘rect_vertical’

可用选项:circle, square, rect_vertical, rect_horizontal。

pixel_density: float, 默认值 0.5

[0, 1] 范围内的调整参数,值越高,散点图越密集。

pixel_spread: str, 默认值 ‘dynspread’

dynspread:根据图像密度动态扩展图像中的像素。 spread:扩展图像中的像素。

title: str,

图表标题

timeout: int(毫秒),默认值 100

确定回调处理新事件的超时时间,而无需等待上一个事件报告完成。对于运行时间很长的回调以及缩放感觉卡顿时,请增加此值。

legend: bool, 默认值 True

如果为 True,则添加基于 Bokeh.models.LinearColorMapper 的图例,

legend_position: str, 默认值 top_right

图表上图例的位置。有效位置有:right, left, bottom, top, top_right, top_left,

bottom_left, bottom_right

unselected_alpha: float [0, 1],默认值 0.2

如果为 True,则使用相同的颜色调色板但透明(alpha=0.2)显示未选定的数据。

xaxis: bool, 默认值 True

如果为 True,则显示带标签的 x 轴

yaxis: bool, 默认值 True

如果为 True,则显示带标签的 y 轴

返回:
类型为 cudashader 热力图(scatter 对象)

cuxfilter.charts.datashader.custom_extensions.InteractiveDatashaderPoints

示例#

from cuxfilter import layouts, themes, DataFrame
from cuxfilter.charts import heatmap
from cuxfilter.sampledata import unemployment_data

cux_df = DataFrame.from_dataframe(unemployment_data)

# this is the colormap from the original NYTimes plot
colors = ["#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce", "#ddb7b1", "#cc7878", "#933b41", "#550b1d"]

chart1 = heatmap(x='Year', y='Month', aggregate_col='rate',
                            color_palette=colors, point_size=10, unselected_alpha=0.2)


d = cux_df.dashboard([chart1], layout=layouts.single_feature, theme=themes.dark)
chart1.view(height=500)

图形图表#

datashader.graph(node_y='y', node_id='vertex', edge_source='source', edge_target='target', x_range=None, y_range=None, add_interaction=True, node_aggregate_col=None, edge_aggregate_col=None, node_aggregate_fn='count', edge_aggregate_fn='count', node_color_palette=None, edge_color_palette=['#000000'], node_point_size=15, node_point_shape='circle', node_pixel_shade_type='eq_hist', node_pixel_density=0.8, node_pixel_spread='dynspread', edge_render_type='direct', edge_transparency=0, curve_params={'curve_total_steps': 100, 'strokeWidth': 1}, tile_provider=None, title='', timeout=100, legend=True, legend_position='top_right', unselected_alpha=0.2, xaxis=False, yaxis=False)#
参数:
node_x: str, 默认值 “x”

节点 cuDF 数据帧的 x 坐标列名

node_y: str, 默认值 “y”

节点 cuDF 数据帧的 y 坐标列名

node_id: str, 默认值 “vertex”

节点 cuDF 数据帧的 node_id/label 列名

edge_source: str, 默认值 “source”

边 cuDF 数据帧的 edge_source 列名

edge_target=”target”,

边 cuDF 数据帧的 edge_target 列名

x_range: tuple, 默认值 (nodes_gpu_dataframe[x].min(),

nodes_gpu_dataframe[x].max()) 要显示的地理散点图的 (min, max) x 维度

y_range: tuple, 默认值 (nodes_gpu_dataframe[y].min(),
nodes_gpu_dataframe[y].max())

要显示的地理散点图的 (min, max) x 维度

add_interaction: {True, False}, 默认值 True
node_aggregate_col=str, 默认值 None,

节点 GPU 数据帧中的列,将在其上运行 mode_aggregate_fn

edge_aggregate_col=str, 默认值 None,

边 GPU 数据帧中的列,将在其上运行 mode_aggregate_fn

node_aggregate_fn={‘count’, ‘mean’, ‘max’, ‘min’},默认值 ‘count’
edge_aggregate_fn={‘count’, ‘mean’, ‘max’, ‘min’},默认值 ‘count’
node_color_palette=bokeh.palettes 或 hex_color_codes 列表/元组,

或颜色名称列表/元组,默认值 bokeh.palettes.Virisdis10

edge_color_palette=bokeh.palettes 或 hex_color_codes 列表/元组,

或颜色名称列表/元组,默认值 [“#000000”]

node_point_size: int, 默认值 8

散点图中的点大小。

node_point_shape: str, 默认值 ‘circle’

可用选项:circle, square, rect_vertical, rect_horizontal。

node_pixel_shade_type: str, 默认值 ‘eq_hist’

datashader.transfer_functions.shade() 函数中的 “how” 参数。可用选项:eq_hist, linear, log, cbrt

node_pixel_density: float, 默认值 0.8

[0, 1] 范围内的调整参数,值越高,散点图越密集。

node_pixel_spread: str, 默认值 ‘dynspread’

dynspread:根据图像密度动态扩展图像中的像素。 spread:扩展图像中的像素。

edge_render_type: str, 默认值 ‘direct’

边缘渲染类型。可用选项为 ‘direct’/’curved’ *注意:弯曲边缘渲染是一个实验性功能,可能会导致内存不足错误

edge_transparency: float, 默认值 0

范围 [0,1] 内的值,用于指定边缘的透明度,其中 1 表示完全透明

curve_params: dict, 默认值 dict(strokeWidth=1, curve_total_steps=100)

如果 edge_render_type=’curved’,则控制曲率和 max_bundle_size

tile_provider: str, 默认值 None

底层地图类型。参见 https://holoviews.org/reference/elements/bokeh/Tiles.html

title: str,

图表标题

timeout: int(毫秒),默认值 100

确定回调处理新事件的超时时间,而无需等待上一个事件报告完成。对于运行时间很长的回调以及缩放感觉卡顿时,请增加此值。

legend: bool, 默认值 True

如果为 True,则添加基于 Bokeh.models.LinearColorMapper 的图例,注意:图例当前仅适用于 pixel_shade_type=’linear’/’log’

legend_position: str, 默认值 top_right

图表上图例的位置。有效位置有:right, left, bottom, top, top_right, top_left,

bottom_left, bottom_right

unselected_alpha: float [0, 1],默认值 0.2

如果为 True,则使用相同的颜色调色板但透明(alpha=0.2)显示未选定的数据(仅限节点)。

xaxis: bool, 默认值 False

如果为 True,则显示带标签的 x 轴

yaxis: bool, 默认值 False

如果为 True,则显示带标签的 y 轴

返回:
类型为 cudashader 图形图表

cuxfilter.charts.datashader.custom_extensions.InteractiveDatashaderGraph

示例#

正在加载 BokehJS ...
import cuxfilter
import cudf

edges = cudf.DataFrame({
    'source': [0, 0, 0, 0, 1, 1, 1, 0, 1, 2, 1, 1, 2, 0, 0],
    'target': [1, 2, 3, 1, 2, 3, 3, 2, 2, 3, 3, 3, 3, 3, 3]
})

nodes = cudf.DataFrame({
    'vertex': [0, 1, 2, 3],
    'x': [-3.3125157356262207,-1.8728941679000854, 0.9095478653907776, 1.9572150707244873],
    'y': [-1.6965408325195312, 2.470950126647949,-2.969928503036499,0.998791515827179]
})

cux_df = cuxfilter.DataFrame.load_graph((nodes, edges))

chart0 = cuxfilter.charts.datashader.graph(node_pixel_shade_type='linear', unselected_alpha=0.2)

d = cux_df.dashboard([chart0], layout=cuxfilter.layouts.double_feature)
chart0.view()