Search code examples
pythonbokeh

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


With below Python Bokeh code, we can create a chart with square scatter markers, however, is there anyway I can make the marker size dynamic? as well as color?

For example,

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

will display the marker's size based on the ratio in the list, and

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

will show each markers' color within red, but gradient based on the ratio?

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)

Is there anyway to do that?


Solution

  • Just replace size=20 with size=[i * 20 for i in [1, 1, 1.5, 2, 2.5]] and color="olive" with a list of required colors, like color=['red', 'green', 'blue', 'yellow', 'grey'].