python bokeh; change Patch colours with CustomJS callback on GMapPlot

六月ゝ 毕业季﹏ 提交于 2019-12-07 03:26:25

The other response changes the fill_color of a bunch of circles to refer to a different column of colors in a column data source (so that all the circles can have their own color) by changing the field attribute. Since you are trying to set just a single color value for the once Patch, you probably want to set value instead of field

cb = CustomJS(args=dict(patch=patch), code ="""
    patch.glyph.fill_color.value = 'blue';
""")

I guess it's possible you might need a trigger there but I don't think so.

The patch and line glyphs are the two glyphs that are a little quirky in the API, because they don't really support vectorized properties like all the other glyphs do.


UPDATE: Perhaps a complete example is clearer. Also FYI the trigger is needed, at least as of current versions (0.12.4).

from bokeh.io import output_file, show
from bokeh.layouts import column
from bokeh.models import CustomJS, Select
from bokeh.plotting import figure

plot = figure()

r = plot.patch(x=[1, 2, 3, 4], y=[1, 2, 2, 1],
               fill_color="firebrick", fill_alpha=0.6, line_color="black")


select = Select(title="Select colors", value="firebrick",
                options = ["firebrick","navy", "olive"])

callback = CustomJS(args=dict(renderer=r, select=select), code ="""
    renderer.glyph.fill_color.value = select.value;
    renderer.trigger('change')
""")
select.callback = callback

output_file("foo.html")

show(column(select, plot))

The patch starts out red. Changing the Select widget in the UI causes the color of the patch to update:

If that's not what you are asking then I have to gently suggest that the question is not clear.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!