Home > Software design >  plotting multiple dataframes as one plot
plotting multiple dataframes as one plot

Time:07-05

I searched through this forum and unfortunatelly I do not know what am I doing wrong. I have three .csv files file1.csv

name     value     type
model1   100.1     all
model2   121.1     all
model3   151.1     all

file2.csv

name     value     type
model1   110.1     one
model2   131.1     one
model3   141.1     one
model4   161.1     one
model5   171.1     one

file3.csv

name     value     type
model1   80.1      two
model2   85.1      two
model3   90.1      two
model4   92.1      two
model5   94.1      two

and i want to make plot which shows all three 'value' bars for each 'name' - thats why I add "type" column.

So I made dataframe from each .csv file and named them df_file1, df_file2, df_file3. So I tried to make a plot:

df_all = pd.concat([df_file1, df_file2, df_file3])
ax = (
     df_all
).plot(kind="bar", rot=45, figsize=(20,6), grid = True, color=['r', 'g', 'y'])

for container in ax.containers:
    ax.bar_label(container)

but unfortunatelly my plot shows three bars for df_file1, five bars for df_file2, five bars for df_file3 instead of three bars for model1, three bars for model2,three bars for model3,three bars for model4 and three bars for model5 with each bar in different column

Is there any way to make a plot just as I disribed it?

CodePudding user response:

IIUC, try enter image description here

  • Related