python做频率统计图 完整版

Caomeinico
• 阅读 643

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

点赞
收藏
评论区
推荐文章
blmius blmius
2年前
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
good123 good123
2年前
python做频率统计图 完整版
yourcodegoesherefrommatplotlibimportpyplotaspltimportpandasaspddeflinearCongruentialMethod(Xo,m,a,c,randomNums,U):randomNums0XoU0randomNums0/m
Stella981 Stella981
2年前
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
2年前
Python3:sqlalchemy对mysql数据库操作,非sql语句
Python3:sqlalchemy对mysql数据库操作,非sql语句python3authorlizmdatetime2018020110:00:00coding:utf8'''
Wesley13 Wesley13
2年前
mysql简单常用语句汇总
1\.常用函数uuid和时间戳SELECTUUID(),UNIX_TIMESTAMP();将时间戳转为日期格式FROM_UNIXTIME(mw.created_at,'%Y%m%d%H:%i:%s')设置参数select@m_no:max(m_no)fromvc_m;set@m
Wesley13 Wesley13
2年前
Oracle 12c DG备库Alert报错ORA
环境是12.2.0.1version,OracleDataGuard备库近段时间一直报错,但是备库主库同步一致,数据一致。20190306T23:42:22.18404808:00Errorsinfile/u01/app/oracle/diag/rdbms/ccdb/ccdb/trace/ccdb_m000_12
Wesley13 Wesley13
2年前
4cast
4castpackageloadcsv.KumarAwanish发布:2020122117:43:04.501348作者:KumarAwanish作者邮箱:awanish00@gmail.com首页:
Wesley13 Wesley13
2年前
mysql timestamp
 select from\_unixtime(m.createdAt, '%Y%m%d %H:%i:%s') from kfrobotaidlog m;select m.customeruid, from\_unixtime(m.createtime, '%Y%m%d %H:%i:%s') as \datetime\, m.kfui
Stella981 Stella981
2年前
Python time模块 返回格式化时间
常用命令  strftimetime.strftime("%Y%m%d%H:%M:%S",formattime)第二个参数为可选参数,不填第二个参数则返回格式化后的当前时间日期201812112:00:00time.strftime('%H:%M:%S')返回当前时间的时分秒time.strftim