通過將絕對頻率除以事件總數得到箱內事件的相對頻率。
因此,您需要計算直方圖,例如,與numpy的
hist, bins = np.histogram(x)
根據您是否然後通過事件的數量每一段內分裂,或總事件數就可以得到不同的地塊。
從左手邊的人可以輕鬆掌握例如在更長的時間內命中率更高(當然這對真實數據可能沒有意義)。從右邊的情節來看,你應該明白,對於中等時鐘時間進行了更多的試驗 - 如果只顯示相對命中,那麼根本沒有看到。
from __future__ import division
import pandas as pd
import numpy as np; np.random.seed(2)
import matplotlib.pyplot as plt
t = np.random.rand(100)*24
hit = np.random.randint(0,2, size=100)
df = pd.DataFrame({"time":t, "hits":hit})
df_miss=df[df.hits == 0]
df_hits=df[df.hits == 1]
bins=np.arange(0,28,4)
hist_hits, bins_ = np.histogram(df_hits.time, bins=bins)
hist_miss, bins_ = np.histogram(df_miss.time, bins=bins)
rel_hits = hist_hits/(hist_hits+hist_miss)*100.
rel_miss = hist_miss/(hist_hits+hist_miss)*100.
rel_hits_n = hist_hits/np.sum(hist_hits+hist_miss)*100.
rel_miss_n = hist_miss/np.sum(hist_hits+hist_miss)*100.
fig , (ax, ax2) = plt.subplots(ncols=2, figsize=(7,3))
ax.bar(bins[:-1], rel_hits, width=4,
color="mediumseagreen", align="edge", ec="k")
ax.bar(bins[:-1], rel_miss, bottom=rel_hits, width=4,
color="tomato", align="edge", ec="k")
ax.set_xticks(bins)
ax.set_ylabel("relative hits and misses [%]")
ax2.bar(bins[:-1], rel_hits_n, width=4,
color="mediumseagreen", align="edge", ec="k", label="hit")
ax2.bar(bins[:-1], rel_miss_n, bottom=rel_hits_n, width=4,
color="tomato", align="edge", ec="k", label="miss")
ax2.set_xticks(bins)
ax2.set_ylabel("normalized hits and misses [%]")
plt.legend()
plt.tight_layout()
plt.show()
後的一些數據。 – Serenity
@serenity在這裏你去 – badhairdude