我有两个链接的散点图,其中的点具有不同的不透明度。问题是当使用框选工具选择某些点时,所有未选择的点将变为相同的不透明度。
我希望未选择的点保持原始的不透明度。可以链接具有不同不透明度的点,因此我无法通过为每个不透明度值创建一个点数组来解决问题。
我是否有办法在绘图API中实现这一目标?
我可以扩展nonselection_glyph
以使其alpha属性接受一个不透明度值数组,例如圆圈标记的alpha属性吗?
import numpy as np
from bokeh.plotting import output_file, figure, gridplot, show
from bokeh.models import ColumnDataSource, Circle
N = 100
max = 100
x1 = np.random.random(size = N) * max
y1 = np.random.random(size = N) * max
a1 = np.random.choice(a = [0.2, 0.5, 1], size = N)
x2 = np.random.random(size = N) * max
y2 = np.random.random(size = N) * max
a2 = np.random.choice(a = [0.2, 0.5, 1], size = N)
output_file('scatter.html')
source = ColumnDataSource(data = dict(x1 = x1, y1 = y1, x2 = x2, y2 = y2,
a1 = a1, a2 = a2))
left = figure(tools = 'box_select, tap', width = 400, height = 400,
x_range = (0,100), y_range = (0,100))
right = figure(tools = 'box_select, tap', width = 400, height = 400,
x_range = (0,100), y_range = (0,100))
points1 = left.circle('x1', 'y1', source = source, size = 10,
fill_color = 'blue', line_color = None, alpha = 'a1')
points2 = right.circle('x2', 'y2', source = source, size = 10,
fill_color = 'blue', line_color = None, alpha = 'a2')
points1.selection_glyph = Circle(fill_color = 'red', line_color = None)
points2.selection_glyph = Circle(fill_color = 'red', line_color = None)
p = gridplot([[left, right]])
show(p)
答案 0 :(得分:1)
试试这个:
import numpy as np
from bokeh.plotting import output_file, figure, gridplot, show
from bokeh.models import ColumnDataSource, Circle
N = 100
max = 100
x1 = np.random.random(size = N) * max
y1 = np.random.random(size = N) * max
a1 = np.random.choice(a = [0.2, 0.5, 1], size = N)
x2 = np.random.random(size = N) * max
y2 = np.random.random(size = N) * max
a2 = np.random.choice(a = [0.2, 0.5, 1], size = N)
source = ColumnDataSource(data = dict(x1 = x1, y1 = y1, x2 = x2, y2 = y2,
a1 = a1, a2 = a2, a1n = a1 * 0.5, a2n=a2*0.5))
left = figure(tools = 'box_select, tap', width = 400, height = 400,
x_range = (0,100), y_range = (0,100))
right = figure(tools = 'box_select, tap', width = 400, height = 400,
x_range = (0,100), y_range = (0,100))
points1 = left.circle('x1', 'y1', source = source, size = 10,
fill_color = 'blue', line_color = None, alpha = 'a1')
points2 = right.circle('x2', 'y2', source = source, size = 10,
fill_color = 'blue', line_color = None, alpha = 'a2')
points1.selection_glyph = Circle(fill_color = 'red', line_color = None)
points2.selection_glyph = Circle(fill_color = 'red', line_color = None)
points1.nonselection_glyph.fill_alpha = "a1n"
points2.nonselection_glyph.fill_alpha = "a2n"
p = gridplot([[left, right]])
show(p)
答案 1 :(得分:0)
我发现nonselection_glyph
可以获取一组不透明度值,但该数组必须位于ColumnDataSource.