日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

Python处理PDF与CDF

發(fā)布時間:2025/4/9 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python处理PDF与CDF 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

在拿到數(shù)據(jù)后,最需要做的工作之一就是查看一下自己的數(shù)據(jù)分布情況。而針對數(shù)據(jù)的分布,又包括pdf和cdf兩類。

下面介紹使用python生成pdf的方法:

  • 使用matplotlib的畫圖接口hist(),直接畫出pdf分布;
  • 使用numpy的數(shù)據(jù)處理函數(shù)histogram(),可以生成pdf分布數(shù)據(jù),方便進(jìn)行后續(xù)的數(shù)據(jù)處理,比如進(jìn)一步生成cdf;
  • 使用seaborn的distplot(),好處是可以進(jìn)行pdf分布的擬合,查看自己數(shù)據(jù)的分布類型;
  • 上圖所示為采用3種算法生成的pdf圖。下面是源代碼。

    from scipy import stats import matplotlib.pyplot as plt import numpy as np import seaborn as snsarr = np.random.normal(size=100)# plot histogram plt.subplot(221) plt.hist(arr)# obtain histogram data plt.subplot(222) hist, bin_edges = np.histogram(arr) plt.plot(hist)# fit histogram curve plt.subplot(223) sns.distplot(arr, kde=False, fit=stats.gamma, rug=True) plt.show()

    ?

    下面介紹使用python生成cdf的方法:

  • 使用numpy的數(shù)據(jù)處理函數(shù)histogram(),生成pdf分布數(shù)據(jù),進(jìn)一步生成cdf;
  • 使用seaborn的cumfreq(),直接畫出cdf;
  • 上圖所示為采用2種算法生成的cdf圖。下面是源代碼。

    from scipy import stats import matplotlib.pyplot as plt import numpy as np import seaborn as snsarr = np.random.normal(size=100)plt.subplot(121) hist, bin_edges = np.histogram(arr) cdf = np.cumsum(hist) plt.plot(cdf)plt.subplot(122) cdf = stats.cumfreq(arr) plt.plot(cdf[0])plt.show()

    ?

    在更多時候,需要把pdf和cdf放在一起,可以更好的顯示數(shù)據(jù)分布。這個實現(xiàn)需要把pdf和cdf分別進(jìn)行歸一化。

    上圖所示為歸一化的pdf和cdf。下面是源代碼。

    from scipy import stats import matplotlib.pyplot as plt import numpy as np import seaborn as snsarr = np.random.normal(size=100)hist, bin_edges = np.histogram(arr) width = (bin_edges[1] - bin_edges[0]) * 0.8 plt.bar(bin_edges[1:], hist/max(hist), width=width, color='#5B9BD5')cdf = np.cumsum(hist/sum(hist)) plt.plot(bin_edges[1:], cdf, '-*', color='#ED7D31')plt.xlim([-2, 2]) plt.ylim([0, 1]) plt.grid()plt.show()

    ?

    轉(zhuǎn)載于:https://www.cnblogs.com/wangjingchn/p/7376470.html

    總結(jié)

    以上是生活随笔為你收集整理的Python处理PDF与CDF的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。