簡體   English   中英

Python:Hvplot 負值着色

[英]Python: Hvplot negative values coloring

我嘗試用 hvplot 做交互式條形圖,但我在那里有負值,想給它們塗上其他顏色。 在此處輸入圖像描述

我嘗試使用 cmap,但它 colors 正值也是負值。 在此處輸入圖像描述

我很樂意提供任何提示或幫助!

謝謝你的好處。

您可以為此使用合成 HoloView plot。

plot1 = df[df['Results']>0].hvplot.bar(y='Results')
plot2 = df[df['Results']<0].hvplot.bar(y='Results')

plot1*plot2

注意:抱歉,我還不能直接發布圖片,因為這是我在 stackoverflow 上的第一個條目,但此鏈接會向您顯示 plot 結果https://i.stack.imgur.com/bnoFg.png

這是下面的完整代碼,您可以將其調整為您的 dataframe:

# 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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM