Hello,
I would like to know if there exists an easy color update for a single patch that I might be missing…
When using a circle glyph, one can update its color conveniently via a ColumnDataSource:
cds_circle = ColumnDataSource(data=dict(x=[5], y=[2], c=["#111aaa"]))
fig.circle(x='x', y='y', color='c', source=cds_circle, radius=2)
def change_circle_color():
new_color = ...
cds_circle.data['c'] = [new_color]
However for fig.patch(x='x', y='y', color='c', source=cds_patch)
we get a value error. Ok, x and y have a different column length compared to c, but also if c is of the same length, the Value Error still appears. It makes sense since defining multiple colors for one patch has no clear meaning.
So I tried around a bit, and came to the conclusion, that there exist these different options:
- Using fig.patches (with one patch entry only)
- storing the GlyphRenderer object
r = fig.patch(...)
and change the color in the callback function viar.glyph.fill_color
andr.glyph.line_color
- Using a tag in the patch (e.g.
fig.patch(..., tags=["some_tag"])
) and find the right renderer in the callback function by using this tag by searching through the list offig.renderers
.
The approach #2 was not available in my code, since that would have led to re-writing a lot of functions to return r
over multiple levels.
#3 would do it, but always searching through all renderers of a figure seems like an over kill.
#1 seems to be the approach which would require the least changes. However I don’t feel very well using patches
which is actually meant for multiple patches, while patch
for a single patch would suffice. The only problem with the single patch is the color update issue.
TLDR:
Can I somehow update the color of a single patch via ColumnDataSource similar to the circle code example above?