1

I have this two data frames df and df1 where

B2B_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
        'B2B': [200,400, 250,
                100,120,200]]
        }
B2C_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
        'B2C': [200,400, 250,
                100,120,200]
        }
df=pd.DataFrame(B2B_1)
df1=pd.DataFrame(B2C_1)

And I didn't know how to plot these two data frames in one plot where axis is based on "Month"

1
  • 1
    try this:pd.concat([df,df1], axis=1).plot(kind='bar') Commented Feb 23, 2021 at 12:28

2 Answers 2

1

pandas plotting functions have the ax parameter in them; if you pass an e.g. matplotlib axis instance to it, it will do its plotting on that axis. So

# make a figure and an axis 
fig, ax = plt.subplots(figsize=(14, 7))

# plot desired quantities; note the `ax=ax` in both
df.plot(x="Month", y="B2B", ax=ax)
df1.plot(x="Month", y="B2C", ax=ax)
Sign up to request clarification or add additional context in comments.

Comments

0

Two DataFrame something like this code

B2B_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
        'B2B': [200,400, 250,
                100,120,200]
        }
B2C_1 = {'Month': ['10/2018','11/2018','12/2018','01/2019','02/2019','03/2019'],
        'B2C': [200,400, 250,
                100,120,200]
        }
  
df=pd.DataFrame(B2B_1)
df1=pd.DataFrame(B2C_1)

x=df['Month']
x1=df["B2B"]
y=df1['Month']
y1=df1["B2C"]  
plt.figure(figsize=(15,8))
plt.bar(x,x1,label="Month")
plt.bar(y,y1,label="Month")
plt.title("Data")
plt.legend(title="Data")
plt.show()

Using that code help to plot the two dataframe easy

Comments

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.