import matplotlib.pyplot as plt
import numpy as np
plt.style.use('ggplot')
mu1,mu2,sigma=100,130,15
#创建两个服从正态分布的变量
x1=mu1+sigma*np.random.randn(1000)
x2=mu2+sigma*np.random.randn(1000)
fig,ax=plt.subplots(1,2,figsize=(12,10))
# ax=fig.add_subplot(1,1,1)
# ax1=fig.add_subplot(1,3,2)
#创建两个柱形图,normed=FALSE说明直方图展示的是频数分布图而不是概率密度图
n,bins,patches=ax[0].hist(x1,bins=50,normed=False,color="darkblue",edgecolor="black")
n,bins,patches=ax[0].hist(x2,bins=50,normed=False,color="orange",edgecolor="black",alpha=0.5)
n,bins,patches=ax[1].hist(x2,cumulative=True,bins=50,normed=False,color="g",edgecolor="black",alpha=0.5)
fig.suptitle('Histograms',fontsize=14,fontweight='bold')
ax[0].xaxis.set_ticks_position('bottom')
ax[0].yaxis.set_ticks_position('left')
ax[0].set_xlabel('Bins')
ax[0].set_ylabel('Number of values in Bin')
ax[0].set_title('Two Frequency Distributions')
ax[1].set_title('A Cumulative Frequency Distributions')
plt.savefig('E:\python\慕课网 python\.idea\photo\histogramt.png',dpi=400,bbox_inches='tight')
plt.show()
Histograms plot
最新推荐文章于 2022-11-24 20:19:22 发布