如何在matplotlib中绘制概率直方图?

时间:2019-10-06 15:13:03

标签: python matplotlib histogram probability

我拥有材料微观结构中存在的孔径数据(以微米^ 2为单位)。我总共有942个毛孔。我使用SciPy加载数据。如果我用手动创建的垃圾箱绘制直方图,则会得到如下直方图:

enter image description here

可以看到,尺寸约为250微米^ 2的孔具有最高的频率,因此存在于微观结构中的可能性最高。

谁能告诉我如何从中获得概率直方图,因为我需要使用Weibull分布函数并将曲线拟合为直方图。

我试图在代码中添加“ density = True”,但是我得到了:

enter image description here

这是我的代码:

import matplotlib.pyplot as plt
import scipy as sci

file1 = 'data_histogram.csv'
file2 = 'data_histogram_1.csv'

data_hist = sci.loadtxt(file1, delimiter=',')
data_hist_1 = sci.loadtxt(file2, delimiter=',')

bins = data_hist[:,0]
data_pores = data_hist_1[:]

plt.rcParams['font.family'] = 'Times New Roman'

fig1 = plt.figure(1, figsize=(9,8))
ax1 = fig1.add_subplot(1,1,1)

ax1.set_xlabel('Pore size', fontsize=14)
ax1.set_ylabel('Freqeuncy', fontsize=14)
ax1.tick_params(direction='out', size=9, width='1.3', labelsize=14)
ax1.hist(data_pores,bins=bins, density=True)

plt.savefig('figure_example1.jpg')
plt.show()enter code here

0 个答案:

没有答案