0

I have 2 data sets that should be stacked bar graphs. But these datasets should be compared against each other as unstacked bar graphs beside each other.

size_array = ("sun", "mon", "tue", "wed", "thr", "fri",)
jan_2022 = [11,12,11,14,18,24]
feb_2022 = [3,3,3,5,7,11]
mar_2022 = [2,2,7,32,103,242]
apr_2022 = [13,13,13,13,13,13]

jan_2023 = [10,11,12,15,16,27]
feb_2023 = [4,3,4,6,8,13]
mar_2023 = [3,4,7,41,145,351]
apr_2023 = [10,9,9,10,9,9]

I am doing the following but it is not outputting the plot I want

df1 = pd.DataFrame({"Jan (2022)":jan_2022, "Feb (2022)":feb_2022, "March (2022)":mar_2022, "April (2022)":apr_2022}, index=size_array)
df1.plot.bar(stacked=True, rot=0, width=0.5, color=plt.cm.Pastel1(np.linspace(0,1,8)))

df2 = pd.DataFrame({"Jan (2023)":jan_2023, "Feb (2023)":feb_2023, "March (2023)":mar_2023, "April (2023)":apr_2023}, index=size_array)
df2.plot.bar(stacked=True, rot=0, width=0.5, color=plt.cm.Pastel1(np.linspace(0,1,8)))

df4 = pd.concat([df1, df2], axis=0, ignore_index=False)
ax = df4.plot.bar(rot=0, width=0.5, color=plt.cm.Pastel1(np.linspace(0,1,8)))

The output I desire is

  1. the data of Jan_2022, Fen_2022, March_2022 and April_2022 stacked on top of each other. Similarly for months of 2023.
  2. these stacked plots of each month grouped by days (size-array), i.e. 2022 month plot side-by-side with the 2023 month for sunday. Similarly, side-by-side bar plots for monday, tuesday ...

enter image description here

yolo_ML
  • 15
  • 5

0 Answers0