I`m looking for a simple solution to plot two bar charts in one plot. I have seen some solutions using subplots but I think there has to be a more convenient way.
As you can see I am ploting the .sum() of my column["VSU"] in two different years.
2014
data = df_obersteir.loc[df_obersteir["Abschlussdatum"].dt.year == 2014]
plot = data.groupby("Vertriebsfunktion").VSU.sum().plot(kind="bar")
2015
data = df_obersteir.loc[df_obersteir["Abschlussdatum"].dt.year == 2015]
plot = data.groupby("Vertriebsfunktion").VSU.sum().plot(kind="bar")
How can I combine these two code fragments in order to get only one graph? It would be nice if we could visually differentiate the graphs by color. Thank you!
EDIT:
Y: I want the sum of my Column VSU / X: I want to have the members of groupby("Vertriebsfunktion")
hi i can't see the data so it's hard to know which graph you want exactly. But I still give you an example of a use of plt.subplots and plt.bar which allows you to have two histograms next to it. I know you are looking for a solution without plt.subplots but there is no easy one to my knowledge.
data1 = df_obersteir.loc[df_obersteir["Abschlussdatum"].dt.year == 2014]
df1=data.groupby("Vertriebsfunktion").VSU.sum()
data2 = df_obersteir.loc[df_obersteir["Abschlussdatum"].dt.year == 2015]
df2 = data.groupby("Vertriebsfunktion").VSU.sum()
f, axes = plt.subplots(nrows=1,ncols=2, sharex=True, sharey=True)
axes[0].bar(df1.iloc[:,0],list(range(df1.shape[0]))) # plt.bar(x,height)
axes[1].bar(df2.iloc[:,0],list(range(df2.shape[0])))
f.set_figheight(12) # control height
f.set_figwidth(18) # control width
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments