def zxt#APP的版本和媒体包名的信息 x=dataapptype y=datapackage pltplotxy#plot函数将x和y作为横轴和纵轴 pltxlabelapptype pltylabelpackage plttitle媒体关系图#标题 pltfigure pltshowdef zft #hist函数获取label列col
可以在函数中加入plt.show()语句,使得图可以在软件上显示,具体修改如下:
def zxt():#APP的版本和媒体包名的信息 x=data['apptype'] y=data['package'] plt.plot(x,y)#plot函数将x和y作为横轴和纵轴 plt.xlabel('apptype') plt.ylabel('package') plt.title('媒体关系图')#标题 plt.figure() plt.show()
def zft(): #hist()函数获取label列,color参数指定直方图的颜色,edgecolor参数指定边缘线条的颜色,alpha参数指定透明度 plt.hist(data['label'],color='blue',edgecolor='black',alpha=0.5) plt.xlabel('Label') plt.ylabel('Count') plt.title('犯罪统计图') plt.figure() plt.show()
def bt(): labels = ['0', '1'] sizes = [sum(data['label'] == 0), sum(data['label'] == 1)] fig1, ax1 = plt.subplots()#subplots()函数创建一个子图 #sizes与labels参数分别表示饼图上各部分占比与对应标签名; #autopct参数用于控制饼图上数字显示的格式;shadow参数指定是否绘制阴影;startangle参数指定起始角度 ax1.pie(sizes, labels=labels, autopct='%1.1f%%', shadow=True, startangle=90) ax1.axis('equal') plt.title('Label比例饼图') plt.figure() plt.show()
def sdt(): sns.scatterplot(x=data['location'],y=data['fea1_hash'],hue=data['label']) plt.xlabel('location') plt.ylabel('fea1_hash') plt.title('媒体信息图') plt.figure() plt.show()
btn8=Button(root,text="制作直线图",command=lambda:zxt()) btn8.place(relx=0.3, rely=0.5, relwidth=0.1, relheight=0.1) btn9 = Button(root, text="制作直方图", command=lambda:zft()) btn9.place(relx=0.4, rely=0.5, relwidth=0.1, relheight=0.1) btn10=Button(root,text="制作饼图",command=lambda:bt()) btn10.place(relx=0.5, rely=0.5, relwidth=0.1, relheight=0.1) btn11=Button(root,text="制作散点图",command=lambda:sdt()) btn11.place(relx=0.6, rely=0.5, relwidth=0.1, relheight=0.1
原文地址: https://www.cveoy.top/t/topic/g02z 著作权归作者所有。请勿转载和采集!