使用 Python 中的一组数据创建概率分布图

Create a Probability Distribution Plot with set of data in Python

我的数据目前是一列电压值(下面的示例),我想创建一个如下所示的图,Y 轴为概率,X 轴为电压。到目前为止,我已经尝试了以下代码,但情节看起来并不像目标。如何获得分布图中 Y 轴上的概率和 x 轴上的电压值?非常感谢您的帮助!

示例电压值: “-0.00183105 -0.0012207 -0.00061035 0 -0.00030518 -0.00091553 -0.00091553 0.00061035 0.0012207 0.00061035 -0.0012207 -0.00213623 -0.00091553 0.00061035 0.0012207 0.00030518 -0.00061035 -0.00061035 “

尝试的代码:

with open(file, 'r') as current:
    for _ in range(9):  # skip the first 12 lines bc logistical info
        next(current)
    print(current.readline(15))
    next(current)
    vc = pd.Series(current).value_counts(normalize=True, sort=False)
    plt.figure(1)
    plt.hist(vc, bins = 20)
    plt.show()

目标:

图片来源:Karimian, S. F.、Modarres, M. 和 Bruck, H. A. (2020)。一种利用声发射波形信息熵检测铝材疲劳裂纹萌生的新方法alloy。工程断裂力学, 223, 106771.

这可能会回答您的问题:

import numpy as np
import matplotlib.pyplot as plt
txt= "-0.00183105 -0.0012207 -0.00061035 0 -0.00030518 -0.00091553 -0.00091553 0.00061035 0.0012207 0.00061035 -0.0012207 -0.00213623 -0.00091553 0.00061035 0.0012207 0.00030518 -0.00061035 -0.00061035 "
from collections import Counter
Vs=[]
for a in txt.split(" "):
    try:
        Vs.append(float(a))
    except:
        print(a)
counts=Counter(Vs)
plt.bar(x=counts.keys(),height=[a/sum(counts.values()) for a in counts.values()],width=3e-4)

示例结果: