Varea conditional color

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.

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…):!Aj99irJinMf5g4o7W93owdtCOILw8g?e=069NMK

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

Please advise!

Posting the dataframe csv and screenshot here. New users can’t do much lol…


dataframe csv:!Aj99irJinMf5g4o67H_UvrWTa_WTlw?e=a0V2NC