2

Suppose I have three dataframes with the same index and same columns names: df1, df2, df3.

df1

Hour | X1 | X2 | X3 | X4
 0   | 15 | 13 | 25 | 37  
 1   | 26 | 52 | 21 | 45 
 2   | 18 | 45 | 45 | 25 
 3   | 65 | 38 | 98 | 14

df2

Hour | X1 | X2 | X3 | X4
 0   | 10 | 13 | 45 | 37  
 1   | 20 | 53 | 31 | 45 
 2   | 13 | 43 | 45 | 25 
 3   | 65 | 32 | 38 | 14

df3

Hour | X1 | X2 | X3 | X4
 0   | 11 | 13 | 25 | 37  
 1   | 21 | 52 | 21 | 45 
 2   | 18 | 41 | 45 | 25 
 3   | 65 | 31 | 98 | 14

Hour is my index. I want to create a barplot. The x-axis is the Hour index and Y-axis is X1 values from each dataframe and I have legends "df1", "df2", and "df3".

A generic format of the plot should be something like enter image description here

1 Answer 1

2

Doing with concat + unstack

pd.concat([df1,df2,df3],keys=[1,2,3]).unstack(0).plot(kind='bar')

enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It is slightly different than what I wanted. Yet, I could figure it out using your solution. Hence, I accept your solution. Indeed, very elegant!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.