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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- python 計算txt文字詞頻率Python
- Trie樹:字串頻率統計排序字串排序
- python如何統計詞頻Python
- nginx根據token做頻率限制Nginx
- python實現詞頻統計Python
- 資料庫redolog切換頻率統計分析資料庫
- 報警系統QuickAlarm之頻率統計及介面封裝UI封裝
- 統計英文名著中單詞出現頻率
- Python統計四六級考試的詞頻Python
- 統計一個字串出現頻率最高的字母/數字字串
- Java、Scala、Python ☞ 本地WordCount詞頻統計對比JavaPython
- 詞頻統計
- Python:對程式做效能分析及計時統計Python
- 等精度頻率計的設計與驗證
- python學生成績管理系統【完整版】Python
- Javafx-【直方圖】文字頻次統計工具 中文/英文單詞統計Java直方圖
- 如何用SPSS繪製頻率多邊形圖SPSS
- 用Python如何統計文字檔案中的詞頻?(Python練習)Python
- 詞頻統計mapreduce
- python自動統計zabbix系統監控覆蓋率Python
- Python做點選率資料預測Python
- 頻率元件 LL元件
- AMD RDNA3 GPU 設計圖曝光,可實現超 3GHz 頻率GPU
- 520悶在家裡做圖( 安卓統計圖MPAndroidChart開發 )安卓Android
- [Python手撕]執行操作使頻率分數最大Python
- 詞語詞頻統計
- 如何計算振盪電路的固有頻率
- MATLAB自帶的函式tabulate統計一個陣列中各數字(元素)出現的頻數、頻率Matlab函式陣列
- P-III曲線水文頻率計算程式(方法)
- Openwrt——頻寬統計助手nlbwmon
- Django(64)頻率認證原始碼分析與自定義頻率認證Django原始碼
- 如何用Python做三階拼圖?Python
- Python計算商品復購率Python
- python TK庫 統計word文件單詞詞頻程式 UI選擇文件PythonUI
- 設計模式完整版設計模式
- 漂亮的頻譜諧波圖必備 Python + PygamePythonGAM
- PostgreSQL全文檢索-詞頻統計SQL
- w10如何設頻率_win10怎樣設定螢幕頻率Win10