python做频率统计图 完整版

good123
• 阅读 864

your code goes here

from matplotlib import pyplot as plt

import pandas as pd

def linearCongruentialMethod(Xo, m, a, c, randomNums, U):

randomNums[0] = Xo

U[0] = randomNums[0] / m

for i in range(1, 10000):

    # Follow the linear congruential method

    randomNums[i] = ((randomNums[i - 1] * a) + c) % m

    U[i] = randomNums[i] / m

print("a = 1597, b = 0, m = 244944")

a = 1597

c = 0

m = 244944

i = 0.01

for i in range(1, 6):

X0 = i * 0.01

print("\n X0 = ", X0, "\n")

noOfRandomNums = 10005

randomNums = [0] * (noOfRandomNums)

U = [0] * (noOfRandomNums)

linearCongruentialMethod(X0, m, a, c, randomNums, U)

intervals = 20

freq = [0] * (intervals)

for j in U:

    x = 1

    x = j * 100 / 5

    freq[int(x)] = freq[int(x)] + 1

mydata = {'Interval  ': ['[0.00,0.05)', '[0.05,0.10)', '[0.10,0.15)', '[0.15,0.20)', '[0.20,0.25)', '[0.25,0.30)',

                         '[0.30,0.35)', '[0.35,0.40)', '[0.40,0.45)', '[0.45,0.50)', '[0.50,0.55)', '[0.55,0.60)',

                         '[0.60,0.65)', '[0.65,0.70)', '[0.70,0.75)', '[0.75,0.80)', '[0.80,0.85)', '[0.85,0.90)',

                         '[0.90,0.95)', '[0.95,1.00)'],

          'Freuency': freq}

df = pd.DataFrame(mydata)

print(df)

data = {'1': freq[0], '2': freq[1], '3': freq[2], '4': freq[3], '5': freq[4], '6': freq[5], '7': freq[6],

        '8': freq[7], '9': freq[8], '10': freq[9], '11': freq[10], '12': freq[11], '13': freq[12], '14': freq[13],

        '15': freq[14], '16': freq[15], '17': freq[16], '18': freq[17], '19': freq[18], '20': freq[19], }

interval = list(data.keys())

frequency = list(data.values())

fig = plt.figure(figsize=(10, 5))

plt.bar(interval, frequency, color='maroon', width=0.4)

plt.show()

print("\na = 51749, b = 0, m = 244944")

a = 51749

c = 0

m = 244944

i = 0.01

for i in range(1, 6):

X0 = i * 0.01

print("\n X0 = ", X0, "\n")

noOfRandomNums = 10005

randomNums = [0] * (noOfRandomNums)

U = [0] * (noOfRandomNums)

linearCongruentialMethod(X0, m, a, c, randomNums, U)

intervals = 20

freq = [0] * (intervals)

for j in U:

    x = 1

    x = j * 100 / 5

    freq[int(x)] = freq[int(x)] + 1

mydata = {'Interval  ': ['[0.00,0.05)', '[0.05,0.10)', '[0.10,0.15)', '[0.15,0.20)', '[0.20,0.25)', '[0.25,0.30)',

                         '[0.30,0.35)', '[0.35,0.40)', '[0.40,0.45)', '[0.45,0.50)', '[0.50,0.55)', '[0.55,0.60)',

                         '[0.60,0.65)', '[0.65,0.70)', '[0.70,0.75)', '[0.75,0.80)', '[0.80,0.85)', '[0.85,0.90)',

                         '[0.90,0.95)', '[0.95,1.00)'],

          'Freuency': freq}

df = pd.DataFrame(mydata)

print(df)

data = {'1': freq[0], '2': freq[1], '3': freq[2], '4': freq[3], '5': freq[4], '6': freq[5], '7': freq[6],

        '8': freq[7], '9': freq[8], '10': freq[9], '11': freq[10], '12': freq[11], '13': freq[12], '14': freq[13],

        '15': freq[14], '16': freq[15], '17': freq[16], '18': freq[17], '19': freq[18], '20': freq[19], }

interval = list(data.keys())

frequency = list(data.values())

fig = plt.figure(figsize=(10, 5))

plt.bar(interval, frequency, color='blue', width=0.4)

plt.show()

好买网(www.goodmai.com)IT技术交易平台

点赞
收藏
评论区
推荐文章
blmius blmius
3年前
MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1
文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s
Stella981 Stella981
3年前
AndroidStudio封装SDK的那些事
<divclass"markdown\_views"<!flowchart箭头图标勿删<svgxmlns"http://www.w3.org/2000/svg"style"display:none;"<pathstrokelinecap"round"d"M5,00,2.55,5z"id"raphael
Stella981 Stella981
3年前
Python3:sqlalchemy对mysql数据库操作,非sql语句
Python3:sqlalchemy对mysql数据库操作,非sql语句python3authorlizmdatetime2018020110:00:00coding:utf8'''
Caomeinico Caomeinico
3年前
python做频率统计图 完整版
yourcodegoesherefrommatplotlibimportpyplotaspltimportpandasaspddeflinearCongruentialMethod(Xo,m,a,c,randomNums,U):randomNums0XoU0randomNums0/m
Wesley13 Wesley13
3年前
4cast
4castpackageloadcsv.KumarAwanish发布:2020122117:43:04.501348作者:KumarAwanish作者邮箱:awanish00@gmail.com首页:
Stella981 Stella981
3年前
Python之time模块的时间戳、时间字符串格式化与转换
Python处理时间和时间戳的内置模块就有time,和datetime两个,本文先说time模块。关于时间戳的几个概念时间戳,根据1970年1月1日00:00:00开始按秒计算的偏移量。时间元组(struct_time),包含9个元素。 time.struct_time(tm_y
Wesley13 Wesley13
3年前
00:Java简单了解
浅谈Java之概述Java是SUN(StanfordUniversityNetwork),斯坦福大学网络公司)1995年推出的一门高级编程语言。Java是一种面向Internet的编程语言。随着Java技术在web方面的不断成熟,已经成为Web应用程序的首选开发语言。Java是简单易学,完全面向对象,安全可靠,与平台无关的编程语言。
Wesley13 Wesley13
3年前
MySQL部分从库上面因为大量的临时表tmp_table造成慢查询
背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_
Python进阶者 Python进阶者
11个月前
Excel中这日期老是出来00:00:00,怎么用Pandas把这个去除
大家好,我是皮皮。一、前言前几天在Python白银交流群【上海新年人】问了一个Pandas数据筛选的问题。问题如下:这日期老是出来00:00:00,怎么把这个去除。二、实现过程后来【论草莓如何成为冻干莓】给了一个思路和代码如下:pd.toexcel之前把这
good123
good123
Lv1
落日熔金,暮云合璧,人在何处
文章
14
粉丝
2
获赞
7