If you know the colors on forehand, the most straightforward way is to specify them as a collection, just as you do with the x, and y values. For example:
xs = [1,2,3,4,5]
ys = [1,2,3,4,5]
colors = [‘blue’] * len(xs)
colors = ‘red’
p1 =figure(height=300, width=300)
r = p1.rect(xs, ys, color=colors, width=.25, height=.25)
Note how i captured the result of p1.rect, this gives you access to the underlying ColumnDataSource attached to those rects. So if you want to change the colors after initial plotting, do something like:
r.data_source.data[‘fill_color’] = ‘green’ # set the third rect to be green
Here is a notebook which shows the entire example:
On Wednesday, November 23, 2016 at 9:46:46 PM UTC+1, [email protected] wrote:
I am trying to work out how individual rects can be managed in the code below, I have some rects in a figure, I would like to change the fill_color for one of them, for example the second one. What is the best way to do this?
code for figure
from bokeh.plotting import figure
from bokeh.io import push_notebook, output_notebook, show
from math import *
p1.rect([1,2,3,4,5], [1,2,3,4,5], width=.1, height=.1, color=“blue”)
h3 = show(p1, notebook_handle=True)
I tried adding the rects one by one in a loop and storing the references.
Then using these references to adjust properties but it is very slow.