资源描述:
《python图形绘制源代码.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.word可编辑.饼图importmatplotlib.pyplotasplt#Piechart,wherethesliceswillbeorderedandplottedcounter-clockwise:labels='Frogs','Hogs','Dogs','Logs'sizes=[15,30,45,10]explode=(0,0.1,0,0)#only"explode"the2ndslice(i.e.'Hogs')fig1,ax1=plt.subplots()ax1.pie(sizes
2、,explode=explode,labels=labels,autopct='%1.1f%%',shadow=True,startangle=90)ax1.axis('equal')#Equalaspectratioensuresthatpieisdrawnasacircle.plt.show()条形图1importnumpyasnp.专业.专注..word可编辑.importmatplotlib.pyplotaspltfrommatplotlib.tickerimportMaxNLocato
3、rfromcollectionsimportnamedtuplen_groups=5means_men=(20,35,30,35,27)std_men=(2,3,4,1,2)means_women=(25,32,34,20,25)std_women=(3,5,2,3,3)fig,ax=plt.subplots()index=np.arange(n_groups)bar_width=0.35opacity=0.4error_config={'ecolor':'0.3'}rects1=ax.bar(
4、index,means_men,bar_width,alpha=opacity,color='b',yerr=std_men,error_kw=error_config,label='Men')rects2=ax.bar(index+bar_width,means_women,bar_width,alpha=opacity,color='r',yerr=std_women,error_kw=error_config,label='Women')ax.set_xlabel('Group').专业.
5、专注..word可编辑.ax.set_ylabel('Scores')ax.set_title('Scoresbygroupandgender')ax.set_xticks(index+bar_width/2)ax.set_xticklabels(('A','B','C','D','E'))ax.legend()fig.tight_layout()plt.show()表格图importnumpyasnpimportmatplotlib.pyplotaspltdata=[[66386,174296
6、,75131,577908,32015],[58230,381139,78045,99308,160454],[89135,80552,152558,497981,603535],[78415,81858,150656,193263,69638],[139361,331509,343164,781380,52269]].专业.专注..word可编辑.columns=('Freeze','Wind','Flood','Quake','Hail')rows=['%dyear'%xforxin(100
7、,50,20,10,5)]values=np.arange(0,2500,500)value_increment=1000#Getsomepastelshadesforthecolorscolors=plt.cm.BuPu(np.linspace(0,0.5,len(rows)))n_rows=len(data)index=np.arange(len(columns))+0.3bar_width=0.4#Initializethevertical-offsetforthestackedbarch
8、art.y_offset=np.zeros(len(columns))#Plotbarsandcreatetextlabelsforthetablecell_text=[]forrowinrange(n_rows):plt.bar(index,data[row],bar_width,bottom=y_offset,color=colors[row])y_offset=y_offset+data[row]cell_text.append(['%1.1f'%(x/1000.0)forxiny_off