python做頻率統計圖 完整版
# 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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70008684/viewspace-2838450/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- matlab統計 頻數、頻率和累積頻率Matlab
- python 計算txt文字詞頻率Python
- Trie樹:字串頻率統計排序字串排序
- nginx根據token做頻率限制Nginx
- CPU主頻,倍頻,外頻,系統匯流排頻率,前端匯流排頻率前端
- python如何統計詞頻Python
- 【python技能】詞頻統計Python
- python實現詞頻統計Python
- 報警系統QuickAlarm之頻率統計及介面封裝UI封裝
- 資料庫redolog切換頻率統計分析資料庫
- matlab統計一個陣列中各元素出現的頻數、頻率Matlab陣列
- 統計一個字串出現頻率最高的字母/數字字串
- 詞頻統計
- Python統計四六級考試的詞頻Python
- 等精度頻率計的設計與驗證
- 頻率元件 LL元件
- Java、Scala、Python ☞ 本地WordCount詞頻統計對比JavaPython
- Javafx-【直方圖】文字頻次統計工具 中文/英文單詞統計Java直方圖
- Python:對程式做效能分析及計時統計Python
- 詞頻統計mapreduce
- 關於高度均衡和頻率均衡的直方圖直方圖
- python學生成績管理系統【完整版】Python
- AMD RDNA3 GPU 設計圖曝光,可實現超 3GHz 頻率GPU
- Python做點選率資料預測Python
- phpcookie控制提交頻率PHPCookie
- 如何計算振盪電路的固有頻率
- python自動統計zabbix系統監控覆蓋率Python
- [Python手撕]執行操作使頻率分數最大Python
- 詞頻統計-------------web版本Web
- 用Python如何統計文字檔案中的詞頻?(Python練習)Python
- 一分鐘瞭解“Matlab統計數值頻率和個數tabulate”Matlab
- Django(64)頻率認證原始碼分析與自定義頻率認證Django原始碼
- P-III曲線水文頻率計算程式(方法)
- 520悶在家裡做圖( 安卓統計圖MPAndroidChart開發 )安卓Android
- 等頻直方圖,計算COST直方圖
- matlab中用於統計矩陣資料頻率,出現次數的函式Matlab矩陣函式
- MATLAB自帶的函式tabulate統計一個陣列中各數字(元素)出現的頻數、頻率Matlab函式陣列
- Matlab 日期頻次統計Matlab