2015-03-31 91 views
-1

我正在进行一个使用python的自动化测试套件,我希望控制台结果以饼图的形式显示,我想要通过并且未能在图表中传递绿色并以红色失败,有没有什么办法可以让我可以从控制台结果创建饼图?如何使用python创建饼图?

+0

http://matplotlib.org/1.4.0/examples/pie_and_polar_charts/pie_demo_features.html – 2015-03-31 05:46:19

+1

实测值在5秒内与谷歌查询!! – 2015-03-31 05:47:04

回答

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() 
+0

我得到这个错误,而输入蛋白 “从pylab进口*” 文件 “C:\ Python27 \ LIB \站点包\ pylab.py”,1号线,在 从matplotlib.pylab进口* 文件“C :\ Python27 \ lib \ site-packages \ matplotlib \ __ init__.py“,第105行,在 导入六个 ImportError:没有模块命名为六 – 2015-03-31 06:07:29

2

You can use matplotlib/pylab

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()