簡體   English   中英

在matplotlib直方圖中排除一定范圍的垃圾箱?

[英]Excluding a certain range of bins in a matplotlib histogram?

我正在使用matplotlib來查看基於MLB的賠率如何分配獲勝。 問題是,因為賠率要么> = 100或<= -100,有一個在我的柱狀圖中間有很大的差距。

有什么方法可以排除某些垃圾箱(特別是-100到100之間的任何垃圾箱),從而使圖表的條形更加流暢?

鏈接到當前直方圖

這是我現在擁有的代碼:

num_bins = 20
fig, ax = plt.subplots()

n, bins, patches = ax.hist(winner_odds_df['WinnerOdds'], num_bins, 
range=range_of_winner_odds)

ax.set_xlabel('Betting Odds')
ax.set_ylabel('Win Frequency')
ax.set_title('Histogram of Favorite Win Frequency Based on Betting Odds (2018)')

fig.tight_layout()
plt.show()

你可以打破你的圖表的x軸的解釋在這里 ,通過繪制於對視覺上看起來像一個積了兩個不同的軸。 重寫以應用於x軸而不是y軸的基本部分是:

f, (axl, axr) = plt.subplots(1, 2, sharey=True)

# plot the same data on both axes
axl.hist(winner_odds_df['WinnerOdds'], num_bins)
axr.hist(winner_odds_df['WinnerOdds'], num_bins)

# zoom-in / limit the view to different portions of the data
axl.set_xlim(-500, -100)  # outliers only
axr.set_xlim(100, 500)  # most of the data

# hide the spines between axl and axr
axl.spines['right'].set_visible(False)
axr.spines['left'].set_visible(False)

axr.yaxis.tick_right()
# How much space to leave between plots
plt.subplots_adjust(wspace=0.15)

請參閱鏈接的文檔,以了解如何通過添加對角折線來進行拋光。 上面的代碼生成的基本版本如下所示: X軸斷裂的正態分布

暫無
暫無

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

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