python四种统计图————赵俊杰

线形图

import matplotlib.pyplot as mpl
import numpy as np
 
#定义数据
ypoints=np.array([1,3,9,25,12,32,5,1])
#数据插入到图表
# mpl.plot(ypoints,'o:g')
# mpl.plot(ypoints,marker='o',linestyle=':',color='g')
mpl.plot(ypoints,marker='o',ls=':',c='r')
mpl.plot(ypoints,marker='o',linestyle=':',color='g',linewidth='2.85')
#设置xy名字
mpl.xlabel('x-label')
mpl.ylabel('y-label')
mpl.title('table')
#图表显示
mpl.show()

 点图

import matplotlib.pyplot as mpl
import numpy as np
 
x = np.array([1,2,3,4,5,6,7,8])
y = np.array([1,4,9,14,7,11,23,18])
sizes= np.array([20,50,100,200,500,1000,60,90])
colors=np.array(['red','green','yellow','cyan','black','beige','magenta','orange'])
# mpl.subplot(1,2,1)
mpl.scatter(x,y,s=sizes,c=colors)
mpl.title('scatter')
#
# x2=np.random.rand(50)
# y2=np.random.rand(50)
# colors2=np.random.rand(50)
# mpl.subplot(1,2,2)
# mpl.scatter(x2,y2,c=colors2)
# mpl.title('scatter')
 
mpl.show()
 

 柱形图

import matplotlib.pyplot as mpl
import numpy as np
 
 
# 定义数据
x = np.array(['math','english','chinese','history','physical'])
y = np.array([88,66,99,119,95])
c = np.array(['red','green','blue','black','yellow'])
# 设置子图1
# mpl.subplot(1,2,1)
# 插入数据
mpl.bar(x,y,color=c,width=0.5)
mpl.title('score')
mpl.xlabel('course')
mpl.ylabel('grede')
 
# 设置子图2
# mpl.subplot(1,2,2)
# 插入数据
# mpl.bar(x,y,color=c,width=0.5)
# mpl.title('score2')
# mpl.xlabel('course2')
# mpl.ylabel('grede2')
 
mpl.show()

饼图

import matplotlib.pyplot as mpl
import numpy as np
 
y = np.array([35,25,25,15])
l=np.array(['basketball','football','volleyball','others'])
c=np.array(['red','green','blue','black'])
mpl.pie(y,labels=l,colors=c,explode=(0,0.2,0,0),autopct='%.1f%%')
mpl.title('nobby')
mpl.savefig('123.png')
mpl.show()

 

你可能感兴趣的:(python)