簡體   English   中英

有沒有辦法在相同的軸上繪制多個累積直方圖,其中數據集是標准化的

[英]Is there a way to plot multiple cumulative histograms on the same axes, where the datasets are normalized

我正在嘗試使用 matplotlib.plt.hist() 在同一軸上繪制兩個數據集。 我希望數據集出現在同一個 y 軸上,這樣每個數據集的 100% 值將出現在圖上的同一位置。 這些數據集包含不同數量的數據。 我正在生成總面積和百分比密度的累積分布圖。 我嘗試使用密度 = True 作為參數,但是這些圖的形狀與單獨繪制時的形狀不同。 這是我迄今為止使用的代碼!


data = pd.Series(condensed['slope'])
data_mtl = pd.Series(montreal['slope'])

fig, ax = plt.subplots(figsize = (60, 20))
ax.hist([data, data_mtl], bins = 200, color=['g','r'], cumulative = True, histtype = 'step')
ax.set_xlabel('ΔCO/ΔCO₂ (ppb/ppm)')
ax.set_ylabel("% Density")

for item in ([ax.title, ax.xaxis.label, ax.yaxis.label] +
             ax.get_xticklabels() + ax.get_yticklabels()):
    item.set_fontsize(50)
    
ax.yaxis.set_major_formatter(ticker.PercentFormatter(xmax=len(data_mtl)))
plt.show()

繪圖生成

編輯:用第 80 個百分位線與密度 = True 分開繪圖

9月1日

9月2日

密度 = True:

一起

假設您對所有圖使用density=Truecumulative=True ,它應該沒問題:

import matplotlib.pyplot as plt
import numpy as np

data1 = np.random.normal(size=100)
data2 = np.random.rand(4000)    
plt.hist(data1, cumulative=True, density=True)
plt.hist(data2, cumulative=True, density=True)
plt.show()

在此處輸入圖片說明

如果您的 x 軸不夠大以包含所有數據並且具有稀疏區域,則它可能看起來“未達到1.0 ”。 我會再次嘗試使用density=True 此外,需要cumulative=True以保證最大bin 高度相同。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM