python - 在 Python 中将直方图转换为曲线

标签 python matplotlib

我有这个代码

df1 = df['T1'].values

df1 = df1 [~np.isnan(df1 )].tolist()

plt.hist(df1 , bins='auto', range=(0,100))
plt.show()

这给了我这张图

enter image description here

和这段代码

df2 = df['T2'].values

df2 = df2 [~np.isnan(df2 )].tolist()

plt.hist(df2 , bins='auto', range=(0,100))
plt.show()

这给了我这个

enter image description here

有什么方法可以将直方图转换为曲线,然后将它们组合在一起?

像这样

enter image description here

最佳答案

可能你想画这样的台阶

import numpy as np
import matplotlib.pyplot as plt

d1 = np.random.rayleigh(30, size=9663)
d2 = np.random.rayleigh(46, size=8083)

plt.hist(d1 , bins=np.arange(100), histtype="step")
plt.hist(d2 , bins=np.arange(100), histtype="step")
plt.show()

enter image description here

关于python - 在 Python 中将直方图转换为曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55582695/

相关文章:

python - 如何压缩整个文件夹(带有子文件夹)并通过 Flask 提供它而不将任何内容保存到磁盘

python - IEP 中 Python 的乘法表?

python - 如何删除列表中特定字符之后的所有字符

python - Pyplot 绘制带有颜色图和 alpha 序列的图像

python - Matplotlib:在对数对数图中绘制垂直箭头

python - 子图未正确填充

python-3.x - anaconda 和 VScode 的问题

python - Django ORM 和 Django REST 框架 : How to make "grouped" arrays?

python - pySpark Reduce抛出Py4JJavaError

python - 如何在现有图中绘制 seaborn pairplot