python做频率统计图 完整版

your code goes here

from matplotlib import pyplot as plt

import pandas as pd

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

1randomNums[0] = Xo 2 3U[0] = randomNums[0] / m 4 5for i in range(1, 10000): 6 7 # Follow the linear congruential method 8 9 randomNums[i] = ((randomNums[i - 1] * a) + c) % m 10 11 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):

1X0 = i * 0.01 2 3print("\n X0 = ", X0, "\n") 4 5noOfRandomNums = 10005 6 7randomNums = [0] * (noOfRandomNums) 8 9U = [0] * (noOfRandomNums) 10 11linearCongruentialMethod(X0, m, a, c, randomNums, U) 12 13intervals = 20 14 15freq = [0] * (intervals) 16 17for j in U: 18 19 x = 1 20 21 x = j * 100 / 5 22 23 freq[int(x)] = freq[int(x)] + 1 24 25mydata = {'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)', 26 27 '[0.30,0.35)', '[0.35,0.40)', '[0.40,0.45)', '[0.45,0.50)', '[0.50,0.55)', '[0.55,0.60)', 28 29 '[0.60,0.65)', '[0.65,0.70)', '[0.70,0.75)', '[0.75,0.80)', '[0.80,0.85)', '[0.85,0.90)', 30 31 '[0.90,0.95)', '[0.95,1.00)'], 32 33 'Freuency': freq} 34 35df = pd.DataFrame(mydata) 36 37print(df) 38 39data = {'1': freq[0], '2': freq[1], '3': freq[2], '4': freq[3], '5': freq[4], '6': freq[5], '7': freq[6], 40 41 '8': freq[7], '9': freq[8], '10': freq[9], '11': freq[10], '12': freq[11], '13': freq[12], '14': freq[13], 42 43 '15': freq[14], '16': freq[15], '17': freq[16], '18': freq[17], '19': freq[18], '20': freq[19], } 44 45interval = list(data.keys()) 46 47frequency = list(data.values()) 48 49fig = plt.figure(figsize=(10, 5)) 50 51plt.bar(interval, frequency, color='maroon', width=0.4) 52 53plt.show()

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

a = 51749

c = 0

m = 244944

i = 0.01

for i in range(1, 6):

1X0 = i * 0.01 2 3print("\n X0 = ", X0, "\n") 4 5noOfRandomNums = 10005 6 7randomNums = [0] * (noOfRandomNums) 8 9U = [0] * (noOfRandomNums) 10 11linearCongruentialMethod(X0, m, a, c, randomNums, U) 12 13intervals = 20 14 15freq = [0] * (intervals) 16 17for j in U: 18 19 x = 1 20 21 x = j * 100 / 5 22 23 freq[int(x)] = freq[int(x)] + 1 24 25mydata = {'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)', 26 27 '[0.30,0.35)', '[0.35,0.40)', '[0.40,0.45)', '[0.45,0.50)', '[0.50,0.55)', '[0.55,0.60)', 28 29 '[0.60,0.65)', '[0.65,0.70)', '[0.70,0.75)', '[0.75,0.80)', '[0.80,0.85)', '[0.85,0.90)', 30 31 '[0.90,0.95)', '[0.95,1.00)'], 32 33 'Freuency': freq} 34 35df = pd.DataFrame(mydata) 36 37print(df) 38 39data = {'1': freq[0], '2': freq[1], '3': freq[2], '4': freq[3], '5': freq[4], '6': freq[5], '7': freq[6], 40 41 '8': freq[7], '9': freq[8], '10': freq[9], '11': freq[10], '12': freq[11], '13': freq[12], '14': freq[13], 42 43 '15': freq[14], '16': freq[15], '17': freq[16], '18': freq[17], '19': freq[18], '20': freq[19], } 44 45interval = list(data.keys()) 46 47frequency = list(data.values()) 48 49fig = plt.figure(figsize=(10, 5)) 50 51plt.bar(interval, frequency, color='blue', width=0.4) 52 53plt.show()

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

点赞
收藏

评论区

加载中...

相关推荐

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

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

Python3:sqlalchemy对mysql数据库操作,非sql语句

Python3:sqlalchemy对mysql数据库操作,非sql语句python3authorlizmdatetime2018020110:00:00coding:utf8'''

python做频率统计图 完整版

yourcodegoesherefrommatplotlibimportpyplotaspltimportpandasaspddeflinearCongruentialMethod(Xo,m,a,c,randomNums,U):randomNums0XoU0randomNums0/m

4cast

4castpackageloadcsv.KumarAwanish发布:2020122117:43:04.501348作者:KumarAwanish作者邮箱:awanish00@gmail.com首页: