Python使用pylab库实现绘制直方图功能示例

作者:早起的小小鸟 时间:2022-12-07 04:48:56 

本文实例讲述了Python使用pylab库实现绘制直方图功能。分享给大家供大家参考,具体如下:

Python直方图


#!/usr/bin/python
# -*- coding: utf-8 -*-
import pylab as pl
dataFile = "dataList.txt"
tempList = []
with open(dataFile,"r") as data:
 for everLine in data:
   arrEverLine = [float(index) for index in everLine.split()]
   tempList.append(arrEverLine[0])
pl.hist(tempList,100)
pl.xlabel("直方图标题", fontproperties='SimHei')
pl.show()

dataList.txt内容

14 2 1 0.5 0.5 0 1 0.5 1.5 18.5
19 2 2 0.5 1 0 1 0.5 0 21
19.5 2 1.5 2 0 0.5 2 0 1 20
17.5 1.5 1 1.5 2 0 1.5 0 0 18.5
19.5 2 2 2 0.5 0 1 0 0.5 19.5
16.5 2 0.5 1 0 0.5 0.5 0 0.5 19.5
15.5 2 1 1.5 0 0 1 0.5 1 17.5
13.5 1.5 1 1 2 0 2 0.5 2 20
14.5 2 1.5 2 0 0 1 0 2 18.5
16 2 2 1.5 1 0.5 1 0 2 19.5
。。。

输出结果

Python使用pylab库实现绘制直方图功能示例

希望本文所述对大家Python程序设计有所帮助。

来源:https://blog.csdn.net/yiduanchengxu/article/details/50264021

标签:Python,pylab库,绘制直方图
0
投稿

猜你喜欢

  • python如何编写类似nmap的扫描工具

    2022-05-09 15:19:44
  • mysqldumpslow用法示例(慢查询)

    2024-01-15 22:42:03
  • WEB开发之注册页面验证码倒计时代码的实现

    2024-04-22 22:32:31
  • SQL Server 自动化管理分区设计方案(图解)

    2011-07-21 17:25:04
  • Python udp网络程序实现发送、接收数据功能示例

    2023-12-03 11:12:52
  • wxpython中利用线程防止假死的实现方法

    2022-01-27 00:45:29
  • Flask框架模板渲染操作简单示例

    2023-06-07 00:02:45
  • python Spyder界面无法打开的解决方法

    2023-03-02 09:12:09
  • PyTorch 迁移学习实战

    2022-07-29 14:17:27
  • Pygame实战之实现扎气球游戏

    2023-06-17 10:17:43
  • 如何保持Oracle数据库的优良性能

    2024-01-14 18:05:32
  • 原生js写的放大镜效果

    2024-04-30 08:51:13
  • go mode tidy出现报错go: warning: “all“ matched no packages的解决方法

    2024-02-04 22:35:14
  • python实现从文件中读取数据并绘制成 x y 轴图形的方法

    2023-04-09 22:43:41
  • 从客户端提升SQL Server数据库性能

    2009-03-06 14:27:00
  • golang flag简单用法

    2024-05-08 10:23:48
  • PHP实现简单注册登录系统

    2024-05-02 17:34:13
  • JS获取页面窗口实际大小函数

    2008-01-28 13:18:00
  • 详解字符串在Python内部是如何省内存的

    2021-04-19 08:19:42
  • Django中的session用法详解

    2023-01-12 11:40:45
  • asp之家 网络编程 m.aspxhome.com