使用python绘制概率密度分布图(简单版)

import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import seaborn as sns

# 数据
data = [
    1932.66, 1989.13, 1929.06, 1898.24, 1925.99, 1952.25, 1934.15, 1911.27, 2039.49, 1916.57,
    1956.14, 1976.60, 1943.77, 1979.83, 2007.93, 1948.32, 1926.80, 1957.77, 2018.95, 1955.47,
    1936.28, 1964.59, 2001.86, 2000.46, 1983.32, 1944.21, 1965.44, 1919.20, 1927.22, 1914.22,
    1951.30, 2073.96, 1951.65, 1922.66, 1938.83, 1940.89, 1935.30, 1929.83, 1920.31, 1936.84,
    1903.23, 1961.68, 1910.05, 1967.49, 1944.28, 1929.93, 1947.74, 1998.52, 2084.09, 1984.61,
    1883.19, 1911.96, 1933.98, 1879.84, 1964.32, 1925.98, 1951.21, 1924.62, 1987.16, 1927.16,
    1889.64, 1923.81, 1928.60, 1905.86, 1950.55, 1998.71, 2006.41, 1912.82, 1902.13, 1971.55,
    1896.19, 1942.12, 1928.60, 1913.60, 1957.83, 1929.95, 1953.88, 1909.56, 1930.49, 2011.94,
    1985.11, 1929.07
]

# 设置样式,移除背景条纹并设置背景为白色
sns.set(style="ticks", rc={"axes.facecolor": "white"})

# 创建绘图对象
plt.figure(figsize=(12, 8))

# 使用seaborn绘制概率密度分布图,保留线条底纹
sns.kdeplot(data, shade=True, color="green", label="Density")

# 添加图表标题和轴标签
plt.title('An underground mine in ChangZhi', fontsize=20, weight='bold')
plt.xlabel('Methane concentration/ppb', fontsize=14)
plt.ylabel('Probability density', fontsize=14)

# 添加图例
plt.legend(title='Legend', title_fontsize='13', fontsize='12')

# 调整网格线样式
plt.grid(True, linestyle='--', linewidth=0.5)

# 显示图表
plt.show()
  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值