有没有办法在散景中为非选择字形设置多个不透明度?
Is there a way to have multiple opacities for nonselection glyph in bokeh?
我有两个链接的散点图,其中的点具有不同的不透明度。问题是,当某些点用 box-select 工具 selected 时,所有未 selected 的点都变成相同的不透明度。
我希望未select编辑的点保持原来的不透明度。可以链接具有不同不透明度的点,所以我无法通过为每个不透明度值制作一个点数组来解决问题。
有什么方法可以在绘图中实现这一点 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)
我发现 nonselection_glyph
可以 获取不透明度值数组,但该数组必须位于 ColumnDataSource.
试试这个:
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)
我有两个链接的散点图,其中的点具有不同的不透明度。问题是,当某些点用 box-select 工具 selected 时,所有未 selected 的点都变成相同的不透明度。
我希望未select编辑的点保持原来的不透明度。可以链接具有不同不透明度的点,所以我无法通过为每个不透明度值制作一个点数组来解决问题。
有什么方法可以在绘图中实现这一点 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)
我发现 nonselection_glyph
可以 获取不透明度值数组,但该数组必须位于 ColumnDataSource.
试试这个:
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)