gpt4 book ai didi

python - 如何通过自定义属性将散点图与 Bokeh python 库链接起来?

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:48 24 4
gpt4 key购买 nike

我有两个使用框选择工具的散点图,并通过 x 值链接。我试图通过 ID 值链接这些图。是否有使用现有 Bokeh API 执行此操作的简单方法?

import numpy as np

from bokeh.plotting import figure, output_file, show, gridplot
from bokeh.models import ColumnDataSource

N = 100
max = 100
x = np.random.random(size=N) * max
y1 = np.random.random(size=N) * max
y2 = np.random.random(size=N) * max
id = np.random.random(size=N) * max

output_file("scatter.html")

source = ColumnDataSource(data=dict(x=x, y1=y1, y2=y2))

TOOLS="box_select"

left = figure(width=400, height=400, tools=TOOLS, x_range=(0,100), y_range=(0,100))
left.circle("x", "y1", source=source, size=10, fill_color="black", line_color=None)

right = figure(width=400, height=400, tools=TOOLS, x_range=(0,100), y_range=(0,100))
right.circle("x", "y2", source=source, size=10, fill_color="black", line_color=None)

p = gridplot([[left, right]])
show(p)

最佳答案

这两个图不是“由 x 坐标链接”:它只是看起来那样,因为您的点恰好在两个图中具有相同的 x 坐标。如果您为每个数据点分配两个不同的 x 坐标(x1x2),您会看到它们实际上是由它们在数据表(不需要手动分配id):

import numpy as np

from bokeh.plotting import figure,output_notebook, show, gridplot
from bokeh.models import ColumnDataSource
output_notebook()
N = 100
max = 100
x1 = [0,10,20,30]
x2 = [50,20,10,70]
y1 = [10,10, 20, 20]
y2 = [30,0,30,0]

source = ColumnDataSource(data=dict(x1=x1, x2=x2, y1=y1, y2=y2))

TOOLS="box_select"

left = figure(width=400, height=400, tools=TOOLS, x_range=(0,100), y_range=(0,100))
left.circle("x1", "y1", source=source, size=10, fill_color="black", line_color=None)

right = figure(width=400, height=400, tools=TOOLS, x_range=(0,100), y_range=(0,100))
right.circle("x2", "y2", source=source, size=10, fill_color="black", line_color=None)

p = gridplot([[left, right]])
show(p)

关于python - 如何通过自定义属性将散点图与 Bokeh python 库链接起来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34138496/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com