給出下面的代碼,我得到了預期的情節。有沒有辦法讓熊貓將 X 標簽繪制為 A 和 B 的組合?我試過傳入x=['A','B']以及x=('A','B')哪個不起作用...
我希望標簽只包括它們。可以旋轉并獲得半可行的解決方案,但我不想實際并排比較子集 B ...
df.pivot(index='B',columns='A',values='Val').plot(kind='bar')
import pandas as pd
df = pd.DataFrame(columns=['A','B','Val'])
for a in range(2):
for b in range(3):
df = df.append({'A':str(a),'B':str(b),'Val':a b},ignore_index=True)
df.plot(kind='bar',x='B',y='Val')

uj5u.com熱心網友回復:
您可以通過設定列A和B索引來創建多索引,然后使用plotwith kind=bar:
df.set_index(['A', 'B']).plot(kind='bar', y='Val')

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/428943.html
標籤:Python 熊猫 matplotlib
上一篇:熱圖上的中心顏色條標簽
下一篇:ValueError:未能找到字體DejaVuSans:style=normal:variant=normal:weight=normal...并且回退到默認字體被禁用
