【发布时间】:2022-12-03 10:22:09
【问题描述】:
我尝试用 hvplot 做交互式条形图,但我在那里有负值,想给它们涂上其他颜色。 enter image description here
我尝试使用 cmap,但它也为正值着色为负值。 enter image description here
我很乐意提供任何提示或帮助!
谢谢你的好处。
【问题讨论】:
标签: conditional-formatting hvplot graph-coloring
我尝试用 hvplot 做交互式条形图,但我在那里有负值,想给它们涂上其他颜色。 enter image description here
我尝试使用 cmap,但它也为正值着色为负值。 enter image description here
我很乐意提供任何提示或帮助!
谢谢你的好处。
【问题讨论】:
标签: conditional-formatting hvplot graph-coloring
您可以为此使用合成 HoloView 图。
例如,使用以下数据框:
df
|名称|结果 | | ------ | ------ | |瑞克|-90| |山姆|40| |凯莉| 80| |铝| -28| 您可以使用以下简单代码将负面结果绘制为红色:
plot1 = df[df['Results']>0].hvplot.bar(y='Results')
plot2 = df[df['Results']<0].hvplot.bar(y='Results')
plot1*plot2
https://i.stack.imgur.com/bnoFg.png
这是下面的完整代码:
# create a dataframe with column 'Name' as index
dict = {'Name':["Rick", "Sam", "Kelly", "Al"],
'Results':[-90, +40, +80, -28]}
df = pd.DataFrame(dict)
df.index=df['Name']
# create 2 hvplots: 1 for positive results, and 1 for negative results
plot1 = df[df['Results']>0].hvplot.bar(y='Results')
plot2 = df[df['Results']<0].hvplot.bar(y='Results')
# layout plot1 and plot2 content on the same frame using a compositional plot
plot1*plot2
【讨论】: