可以通过 Python Bokeh 创建具有动态大小和颜色的形状图表

Possible to create shape chart with dynamic size and color by Python Bokeh

使用下面的 Python Bokeh 代码,我们可以创建一个带有方形散点标记的图表,但是,无论如何我可以使标记大小动态化吗?还有颜色?

例如,

size = [1, 1, 1.5, 2, 2.5] 

将根据列表中的比例显示标记的大小,并且

color = [1, 1, 1.5, 2, 2.5]
color_base = "red"

会在红色内显示每个标记的颜色,但会根据比例进行渐变?

from bokeh.plotting import figure, output_file, show

#output to static HTML file
output_file("square.html")

p = figure(plot_width=400, plot_height=400)

#add a square renderer with a size, color, and alpha
p.square([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="olive", alpha=0.5)

#show the results
show(p)

有办法吗?

只需将 size=20 替换为 size=[i * 20 for i in [1, 1, 1.5, 2, 2.5]] 并将 color="olive" 替换为所需颜色的列表,例如 color=['red', 'green', 'blue', 'yellow', 'grey'].