import numpy as np
import matplotlib.pyplot as plt
from pandas import Series, DataFrame
# 创建一个10行4列的DataFrame
df = DataFrame(
np.random.randint(1,10,40).reshape(10,4),
columns = {'A','B','C','D'}
)
df
B A D C
01384123192657131297442475214569815723518421699438
# kind='bar'是柱形图,默认为line
df.plot(kind='bar')
<matplotlib.axes._subplots.AxesSubplot at 0x1ee7b401d30>
plt.show()
# 横柱形图
df.plot(kind='barh')
# stacked=True堆叠
df.plot(kind='bar',stacked=True)
plt.show()
df.plot(kind='area')
plt.show()
# 画一行
df.iloc[5].plot()
plt.show()
# 画10行for i in df.index:
df.iloc[i].plot(label=str(i))
plt.legend()
plt.show()
# 画一列
df['A'].plot()
plt.show()
df.T
0123456789
B 2797986461
A 2553617759
D 1649181485
C 9524511429