项目4-直方图及正态分布曲线等处理
一.基础知识:
https://www.cnblogs.com/quietwalk/p/8243536.html
https://www.cnblogs.com/luckyboy314/p/11715643.html
二.参考:
https://blog.csdn.net/jiangjiang_jian/article/details/80664709
https://blog.csdn.net/qq_43613819/article/details/115637728
https://blog.csdn.net/weixin_43170073/article/details/90383317
https://blog.csdn.net/qq_36056219/article/details/112118602
https://cloud.tencent.com/developer/article/1178417
https://blog.csdn.net/weixin_48615832/article/details/108188652
三.代码:
代码1:
import numpy as np import scipy.stats as stats import matplotlib.pyplot as plt h = [186, 176, 158, 180, 186, 168, 168, 164, 178, 170, 189, 195, 172, 187, 180, 186, 185, 168, 179, 178, 183, 179, 170, 175, 186, 159, 161, 178, 175, 185, 175, 162, 173, 172, 177, 175, 172, 177, 180] h.sort() hmean = np.mean(h) hstd = np.std(h) pdf = stats.norm.pdf(h, hmean, hstd) print(pdf ) plt.plot(h, pdf) plt.show()
代码2:
import numpy as np import pandas as pd import matplotlib.pyplot as plt #构造一组随机数据 s = pd.DataFrame(np.random.randn(1000),columns = ['value']) print(s) #画散点图和直方图 fig = plt.figure(figsize = (10,6)) ax1 = fig.add_subplot(2,1,1) # 创建子图1 ax1.scatter(s.index, s.values) plt.grid() ax2 = fig.add_subplot(2,1,2) # 创建子图2 s.hist(bins=30,alpha = 0.5,ax = ax2) s.plot(kind = 'kde', secondary_y=True,ax = ax2) plt.grid() plt.show()
代码3:
import pandas as pd import matplotlib.pyplot as plt df = pd.read_excel('cs.xls',header=0,index_col=0) print(df) plt.rcParams['font.sans-serif']='SimHei' plt.rcParams['axes.unicode_minus']=False #直方图 fig = plt.figure() ax = fig.add_subplot(1,1,1) ax.hist(df['Chinese'],bins=30) plt.title('Chinese score') plt.xlabel('score') plt.ylabel('Total number') plt.show()