我尝试用 hvplot 制作交互式条形图,但我在那里有负值,并且想将它们着色为其他颜色。 [在此输入图像描述][1]
我尝试使用 cmap,但它也会将正值涂成负值。 [在此输入图像描述][2]
您可以为此使用组合 HoloView 图。
plot1 = df[df['Results']>0].hvplot.bar(y='Results')
plot2 = df[df['Results']<0].hvplot.bar(y='Results')
plot1*plot2
注意:抱歉,我还不能直接发布图像,因为这是我在 stackoverflow 上的第一篇文章,但此链接将向您显示绘图结果
这里是下面的完整代码,您可以将其调整为您的数据框:
# 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