import matplotlib.pyplot as plt
import pandas as pd
data = pd.Series([4, 5, 6], index=['A','B','C'])
fig = plt.figure(figsize=(7, 5), dpi=90) # 聲明畫布1
ax = fig.add_subplot(1,1,1) # 聲明繪圖區(qū)
x, y = data.index, data.values
rects = plt.bar(x, y, color='dodgerblue', width=0.35, label='label1')
plt.grid(linestyle="-.", axis='y', alpha=0.4)
plt.legend()
plt.tight_layout()
for rect in rects: #rects 是三根柱子的集合
height = rect.get_height()
plt.text(rect.get_x() + rect.get_width() / 2, height,
str(height),
size=15,
ha='center',
va='bottom')
for a,b in zip(x,y):
plt.text(a, b-0.2,'%.2f'%b, ha = 'center',va = 'bottom',fontsize=15)
plt.show()