import matplotlib.pyplot as plt
df = pd.DataFrame({'Percent': [0.05, 0.03, 0.01]}, index=['Inconformity', 'OutofVision', 'None'])
import numpy as np
plt.figure(figsize=(8,6))
x=np.arange(len(df.index))
y=np.array(list(df['Percent']))
xticks1=list(df.index)
plt.bar(x,y,width =0.2, align='center', color=['g','b', 'c'],alpha=0.6)
plt.ylim((0, 1))
plt.xticks(x,xticks1,size='small',rotation=30)
plt.xlabel('Item')
plt.ylabel('百分比')
for a,b in zip(x,y):
plt.text(a, b+0.05, '%.2f' % b, ha='center', va= 'bottom',fontsize=16)
ax = plt.gca()
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
plt.ylim(0, 1)
plt.show()
|