-
Notifications
You must be signed in to change notification settings - Fork 0
/
pseudorandom.py
50 lines (41 loc) · 1.2 KB
/
pseudorandom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from sympy import *
import random
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
import math
n=2000
T= [0]*n
L=[0]*n
#print(l)#randint(low=1, high=100, size=10**3)
for i in range(0,n):
l = np.random.random()
L[i]=l
#print( random.uniform(0.0,1) )
#print(L[i])
T[i] = -math.log(L[i])
#print(T)
#print(T)
# 设置matplotlib正常显示中文和负号
matplotlib.rcParams['font.sans-serif']=['SimHei'] # 用黑体显示中文
matplotlib.rcParams['axes.unicode_minus']=False # 正常显示负号
# 随机生成(10000,)服从正态分布的数据
data = T
print(data)
"""
绘制直方图
data:必选参数,绘图数据
bins:直方图的长条形数目,可选项,默认为10
normed:是否将得到的直方图向量归一化,可选项,默认为0,代表不归一化,显示频数。normed=1,表示归一化,显示频率。
facecolor:长条形的颜色
edgecolor:长条形边框的颜色
alpha:透明度
"""
plt.hist(data, bins=10, density=1, facecolor="blue", edgecolor="black", alpha=0.7)
# 显示横轴标签
plt.xlabel("区间")
# 显示纵轴标签
plt.ylabel("频数/频率")
# 显示图标题
plt.title("频数/频率分布直方图")
plt.show()