☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Varea conditional color

Community Support
kai2810
kai2810

Hi everyone, just picked up python about 2mths ago and trying to visualize some data that I have been playing with.

I’m trying to recreate a “cloud” indicator for stock analysis, where if span_a > span_b, the color of the varea is green. if span_a < span_b, the color of the varea is red.

Screenshot is from a stock trading tool where you can see green and red bands.

What have you tried that did NOT work as expected?
I found this thread, somewhat similar to what I want to do, achieved using the transform function and define a color mapping.
https://discourse.bokeh.org/t/bokeh-bar-chart-is-is-possible-to-have-conditional-formatting/1991

So I tried stitching the VAREA function along with that transform and CategoricalColorMapper concept. But VSCode printed out the index of the dataframe along with the corresponding list of boolean values. (see screenshot)

kumo_shader = CategoricalColorMapper(palette=["#4CAF50", "#FF5252"], factors=[df.span_a-df.span_b >= 0, df.span_a-df.span_b < 0])

p.varea(x=df.index, y1=df.span_a, y2=df.span_b, color={'field': 'rate', 'transform': kumo_shader}, fill_alpha=0.5)

Vscode printout (can only share via my own Onedrive, new user can only post one media file…):

Thinking about this… it kinda makes sense it will return like that. But I’m stuck on how to make this work.

Please advise!

⌁   Link to post

End of archived discussion · Replies are disabled