# Pandas 在 Matplotlib 柱状图上绘制多列图

``````import pandas as pd

data=[["Rudra",23,156,70],
["Nayan",20,136,60],
["Alok",15,100,35],
["Prince",30,150,85]
]

df=pd.DataFrame(data,columns=["Name","Age","Height(cm)","Weight(kg)"])
print(df)
``````

``````     Name  Age  Height(cm)  Weight(kg)
0   Rudra   23         156          70
1   Nayan   20         136          60
2    Alok   15         100          35
3  Prince   30         150          85
``````

## 在单条形图中为每个观测值绘制多列的条形图

``````import pandas as pd
import matplotlib.pyplot as plt

data=[["Rudra",23,156,70],
["Nayan",20,136,60],
["Alok",15,100,35],
["Prince",30,150,85]
]

df=pd.DataFrame(data,columns=["Name","Age","Height(cm)","Weight(kg)"])
df.plot(x="Name", y=["Age", "Height(cm)", "Weight(kg)"], kind="bar",figsize=(9,8))
plt.show()
``````

## 叠加单条形图中每个观测值的多列条形图

``````import pandas as pd
import matplotlib.pyplot as plt

employees=["Rudra","Alok","Prince","Nayan","Reman"]
earnings={
"January":[10,20,15,18,14],
"February":[20,13,10,18,15],
"March":[20,20,10,15,18],
}

df=pd.DataFrame(earnings,index=employees)

df.plot(kind="bar",stacked=True,figsize=(10,8))
plt.legend(loc="lower left",bbox_to_anchor=(0.8,1.0))
plt.show()
``````