Home > OS >  How to group stacked barplots? (use same label for several stacked barplots)
How to group stacked barplots? (use same label for several stacked barplots)

Time:11-27

I have data structured like below. What I want is to create stacked barplots per individual and only show the x label grouped. However, in my attempt it repeats the group label for every individual:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

df = pd.DataFrame(
        {'Group':["A","A","B","B","C","C","C","D"],
         'Individual':["ind1","ind2","ind3","ind4","ind5","ind6","ind7","ind8"],
         'Component1':list(np.random.random(8)),
         'Component2':list(np.random.random(8)),
         'Component3':list(np.random.random(8)),
         'Component4':list(np.random.random(8))
        })

df.plot(x="Group", y=["Component1","Component2","Component3","Component4"], kind="barh", 
                  stacked=True,  legend=None, width=1, xlabel="")

This is the horizontal barplot with grouped labels

  • Related