简体   繁体   中英

I need a bar graph with three variables at the same time

I need a bar graph with three columns at the y axis: rating_standard, rating_rapid, rating_blitz.

I attach a graph similar to my request.

df_7 = df3[(df3['fide_id'] == 14109336)]

df_7

fide_id year month rating_standard rating_rapid rating_blitz
146116 2015 1 2530.0 2599.0 2540.0
146116 2015 2 2530.0 2530.0 2530.0
.....
146116 2021 3 2546.0 2546.0 2546.0
146116 2021 4 2546.0 2521.0 2608.0

看看这个

assuming your df_7 is a pandas DataFrame, there are two ways to do this:

easiest way :

df_7.plot(kind='bar',x='month',y=['rating_standard','rating_rapid','rating_blitz'])

another way using seaborn , you can first change the way the data is stored in it like this:

df = df.melt(id_vars=['month'], 
        value_vars=['rating_standard','rating_rapid','rating_blitz'], 
        var_name='rating',
        value_name='value', 
        )

it will make the table as:

    month   rating      value
0   1   rating_standard 2530.0
1   2   rating_standard 2530.0
2   3   rating_standard 2546.0
3   4   rating_standard 2546.0
4   1   rating_rapid    2599.0

where those rating columns are now a variable, ie each row in the original table now corresponds to 3 rows in the new table. Then you can use seaborn as the following:

import seaborn as sns
sns.barplot(data=df, x='month', y='value', hue='rating')

示例输出

let me know if you want to be exactly like the image you shared, like the month names, colors, etc. then we can make some changes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM