我有如下結構的資料。我想要的是為每個人創建堆疊的條形圖,并且只顯示分組的 x 標簽。但是,在我的嘗試中,它為每個人重復了組標簽:
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="")
這是帶有重復組標簽的堆疊條形圖的
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/367147.html
標籤:Python 熊猫 matplotlib
