[英]Matplotlib histogram where bins are defined range of FLOATS and colored by it?
[英]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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.