matplotlib小试牛刀

import pandas as pd
import matplotlib.pyplot as plt #plt用于显示图片
import matplotlib as mpl

df = pd.read_excel("..\\data\\matplot-test-data-network-score.xlsx")
vip = ['张三','李四','王五']
data = df[df['姓名'].isin(vip)].set_index(["姓名",'月份'])

data1 = data['综合'].unstack()
data2 = data['语文'].unstack()
data3 = data['数学'].unstack()
data4 = data['英语'].unstack()
mpl.style.use('ggplot')
# 可以用下面这句来查看所有可支持的style
# plt.style.available

fig = plt.figure(figsize=(8,20), dpi=80)
ax1 = fig.add_subplot(4, 1, 1)
ax2 = fig.add_subplot(4, 1, 2)
ax3 = fig.add_subplot(4, 1, 3)
ax4 = fig.add_subplot(4, 1, 4)

# 以上5行可以用下面一行来代替
# fig, (ax1, ax2, ax3, ax4) = plt.subplots(nrows=4, ncols=1, sharey=True, figsize=(8,30))

data1.plot(kind='bar',legend=False, ax=ax1,table=True)   #data1的行索引是绘图的x轴,列索引是图例项
data2.plot(kind='bar',legend=False, ax=ax2)
data2.plot(kind='bar',legend=False, ax=ax3)
data2.plot(kind='bar',legend=False, ax=ax4)

ax1.set(title='综合', ylabel='分数')

fig.suptitle('2019年1-6月得分趋势图', fontsize=14, fontweight='bold')
fig.savefig("123.png")

你可能感兴趣的:(matplotlib小试牛刀)