Using Pandas and Python I am trying to achieve a barplot.
The data is imported from a CSV into a dataframe in Pandas.
There are several groups of bars which are grouped according to a specific row value in one of the columns, which are the categories: A, B, C, D, E. These categories are given by the values in a column in the CSV called category. As we can see from the attached picture, A corresponds to the light grey, B to the lighest blue and so on until E.
Each of the rows have two columns (COLUMN1, COLUMN2) that are relevant for the y-values (from 1 to 5, this give the heights of the bars) in the barplot. So looking at the attached picture: from column 1 the not-semi-transparent-bars are constructed and from COLUMN2 the semi-transparent-bars are constructed.
EDIT
Here is how the layout of the data in the imported CSV/dataframe is:
Category COLUMN1 COLUMN2 Month
A 0.2 3 Jan
B 0.3 5 Jan
C 0.7 4 Jan
D 0.4 3 Jan
E 0.8 5 Jan
A 0.3 4 Feb
B 0.75 4.5 Feb
END EDIT
I have managed to make the plot with the groupings of 5 bars of the not-semi-transparent bars, but I have no clue how to get the semi-transparent bars into the same plot as is shown in the attached picture. Any suggestions? My problem is that I need to add the values from COLUMN2 as semi-transparent bars (they don't have to be semi-transparent, but it could be the easiest for beeing able to distinguish).
This is the code I have so far:
import pandas as pd
df=pd.read_csv("filename_for_import.csv",
names=["Category", "COLUMN1", "COLUMN2", "Month"],
encoding="UTF-8")
order = ['Jan', 'Feb', 'Mar', 'Apr']
d = pd.pivot_table(df, index='Month', columns='Category',
values='COLUMN1').loc[order].plot(kind='bar', grid='True')
EDIT 2
Just realized a potential issue depending on the data used. Adjusted the value of A in COLUMN1 to be bigger than B on the first row, to illustrate an example.
Category COLUMN1 COLUMN2 Month
A 4.5 3 Jan
B 0.3 5 Jan
C 0.7 4 Jan
D 0.4 3 Jan
E 0.8 5 Jan
A 0.3 4 Feb
B 0.75 4.5 Feb
Discovered that the non-semi-transparent-bars are placed on top, making it impossible to see the the semi-transparent-bars in the cases when they are lower than the non-semi-transparent bars. It seems like changing the order in the code provided below by Parfait. Also switching between col/ax 1 and 2 in the same code doesn't seem to make any difference. It appears as if the non-transparent bars are always placed on top no matter what. Is there some way to override this?