python制作多种常用统计图

一:线形图

import matplotlib.pyplot as plt 
import numpy as np 
import seaborn as sns 
import warnings ****#忽略告警信息****
warnings.filterwarnings("ignore") ****#忽略告警信息****
x = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15] 
y = [12,13,15,12,14,24,35,32,27,29,21,27,26,21,10] 

plt.figure(figsize=(15,5)) #设置面板大小
plt.plot(x,y) 
plt.title('Fifteen days of weather change') #标题
plt.xlabel('date') 
plt.ylabel('℃') 
plt.show() 

在这里插入图片描述
二:直方图+线状图

import numpy as np
import matplotlib.pyplot as plt
x = np.array([1,2,3,4,5,6,7,8])
y = np.array([4,5,6,12,2,3,10,15])
plt.plot(x,y,'b',lw=2)#x轴,y轴,线条颜色b:blue蓝色
x = np.array([1,2,3,4,5,6,7,8])
y = np.array([15,13,27,36,11,16,20,15])
plt.bar(x,y,0.2,alpha=0.5,color='r')
plt.show()

在这里插入图片描述
三:柱状图

y1 = [12,14,25,12,14,24,35,34,21,29,24,28,20,21,10] 
y2 = [24,25,22,25,21,24,10,27,26,25,28,29,23,21,27] 
x1 = [0.25,1.25,2.25,3.25,4.25,5.25,6.25,7.25,8.25,9.25,10.25,11.25,12.25,13.25,14.25] 
x2 = [0.75,1.75,2.75,3.75,4.75,5.75,6.75,7.75,8.75,9.75,10.75,11.75,12.75,13.75,14.75] 
 
plt.figure(figsize=(10,5))
plt.bar(x1,y1,width = 0.5,label = 'city A') 
plt.bar(x2,y2,width = 0.5,label = 'city B') 
plt.title('Fifteen days of weather change') 
plt.xlabel('date') 
plt.ylabel('℃') 
plt.legend() 
plt.show() 

在这里插入图片描述
四:点状图

plt.figure(figsize=(10,5))
plt.scatter(x,y) 
plt.title('Fifteen days of weather change') 
plt.xlabel('date') 
plt.ylabel('℃') 
plt.show() 

在这里插入图片描述

x = range(20) 
y = x + np.random.randn(20)*1.5  
plt.figure(figsize=(10,5)) 
plt.plot(x,y,'*') 
plt.plot(x,x) 
plt.title('x VS y') 
plt.xlabel('X') 
plt.ylabel('Y') 
plt.legend(('real data','fitted line')) 
plt.show() 

在这里插入图片描述五:盒状图

y1 = [123,144,225,132,154,224,35,341,241,295,243,28,230,211,110] 
y2 = [124,225,221,252,231,243,102,217,216,25,238,229,23,21,127] 
plt.figure(figsize=(10,5)) 
plt.boxplot([y1,y2]) 
plt.xticks([1,2],['A','B'])
plt.xlabel('different city')
plt.show() 

在这里插入图片描述

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值