import numpy as np import matplotlib.pyplot as plt import pandas as pd from scipy.stats import norm from scipy.stats import shapiro import statistics data= pd.read_csv('ethercat3.csv',usecols=['Time']) clo_t = data['Time'].tolist() stat, p = shapiro(clo_t) print('stat=%.3f, p=%.3f \n' % (stat, p)) if p > 0.05: print("Data follows Normal Distribution") else: print("Data does not follow Normal Distribution")
[root@centos7 ~]# python3 norm_test.py /usr/local/lib64/python3.6/site-packages/scipy/stats/morestats.py:1681: UserWarning: p-value may not be accurate for N > 5000. warnings.warn("p-value may not be accurate for N > 5000.") stat=0.636, p=0.000 Data does not follow Normal Distribution
import numpy as np import matplotlib.pyplot as plt import pandas as pd from scipy.stats import norm from scipy.stats import shapiro import statistics data= pd.read_csv('ethercat3.csv',usecols=['Time']) clo_t = data['Time'].tolist() stat, p = shapiro(clo_t[0:4000]) print('stat=%.3f, p=%.3f \n' % (stat, p)) if p > 0.05: print("Data follows Normal Distribution") else: print("Data does not follow Normal Distribution")
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
# 设置matplotlib正常显示中文和负号
matplotlib.rcParams['font.sans-serif']=['SimHei'] # 用黑体显示中文
matplotlib.rcParams['axes.unicode_minus']=False # 正常显示负号
# 随机生成(10000,)服从正态分布的数据
data = np.random.randn(10000)
"""
绘制直方图
data:必选参数,绘图数据
bins:直方图的长条形数目,可选项,默认为10
normed:是否将得到的直方图向量归一化,可选项,默认为0,代表不归一化,显示频数。normed=1,表示归一化,显示频率。
facecolor:长条形的颜色
edgecolor:长条形边框的颜色
alpha:透明度
"""
plt.hist(data, bins=40, normed=0, facecolor="blue", edgecolor="black", alpha=0.7)
# 显示横轴标签
plt.xlabel("区间")
# 显示纵轴标签
plt.ylabel("频数/频率")
# 显示图标题
plt.title("频数/频率分布直方图")
plt.show()