簡體   English   中英

與直接繪制數據集不同的條形圖 colors

[英]different colors of the bars from directly plotting dataset

我可以在我的條形圖上直接從 pandas plot 有不同的 colors 而不指定它們。 這就是我所指的:我有這個 dataframe:

 df
 Personnage    Puissance
 J. Wick        82
 J. Bond        72
 J. Bourne      85
 J. Rambo       91
 J. McLane      83

當我使用df.plot(kind='bar')時,我所有的條都是藍色的。我想使用一個參數來獲得不同的 colors 而無需手動指定它們。

您是否對seaborn開放態度:

import seaborn as sns
sns.barplot(x='Personnage', y='Puissance', data=df)

Output:

在此處輸入圖像描述

使用 matplotlib,您可以循環數據:

for idx, row in df.iterrows():
    plt.bar(row['Personnage'], row['Puissance'])

你會得到幾乎相同的 output 不同的 alpha:

在此處輸入圖像描述

暫無
暫無

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

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