Python visualisation 2 Bar charts in one plot grouped by Column and year

MLAlex

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")

Raphaël Gervillié

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.

edited at
0

Comments

0 comments
Login to comment

Related

Pandas Bar plot, how to annotate grouped horizontal bar charts

Grouped and stacked bar charts in Python Plotly

ggplot: grouped bar plot with column group ordering

How to plot two grouped bar charts next to each others

How to get a grouped bar plot in Python in which one of the bar is stacked and the others are not?

How can I create a grouped bar plot visualisation in R using the given dataset

Stacked and grouped bar charts

2grouped bar plot in R

Plot multiple grouped bar chart with matplotlib in python

How to bar plot a python dataframe grouping by more than one column

r - ggplot2 - Add differences to grouped bar charts

How to create a figure of subplots of grouped bar charts in python

Seaborn grouped Bar plot

Grouped bar plot R

Making a grouped bar plot

While plotting bar plot in python, how can I make it stacked for 2 columns and not stacked for one column in a pandas data frame of 3 columns?

Standard column width in facetted and grouped ggplot bar plot

Grouped bar plot column width uneven due to no data

How to combine different DataFrames into one grouped bar plot

bar chart in python grouped by the sex column

ggplot2 bar chart labels for one column for data grouped by multiple columns

Grouped bar charts with intersecting ticks

Creating two bar charts for one variable in the same plot in R

Multiple sets of grouped bar charts (on the same plot) without using "transforms" in r plotly

How to position labels on grouped bar plot columns in ggplot2

Plot graph of difference in one column for grouped columns of pandas dataframe

Plot count of one column versus time grouped by two columns

sort x-axis in a certain order for grouped bar plot in Python

Stacked Bar chart of many columns grouped by the values of one column (Pandas)