我正在使用python进行自动化测试套件,我希望控制台结果以饼图的形式显示,我希望通过并且无法进入图表,传入绿色并失败红色,是否有任何方式我可以从控制台结果创建饼图吗?
答案 0 :(得分:2)
from pylab import *
# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
# The slices will be ordered and plotted counter-clockwise.
labels = 'Pass', 'Fail'
fracs = [75, 25]
explode=(0, 0.05, 0, 0)
pie(fracs, explode=explode, labels=labels,
autopct='%1.1f%%', shadow=True, startangle=90)
title('Pass/Fail', bbox={'facecolor':'0.8', 'pad':5})
show()
答案 1 :(得分:2)
import matplotlib.pyplot as plt
#change these 2 variables to suit your needs
nPass = 5857
nFail = 1362
plt.rcParams.update({'font.size': 22}) #adjust font size; not really needed
plt.pie([nPass, nFail],
colors=["green","red"],
labels=["Pass", "Fail"],
autopct='%1.1f%%',
startangle=90)
plt.axis('equal') #ensure pie is round
plt.show()