[英]How to plot binary colored histogram in Python?
要獲得類似 seaborn 中的重疊條形圖,它比 R 中的一行代碼稍微復雜一些。
您實際上需要創建兩個圖,一個用於“背景”,一個用於“前景”
stacked_bar_data["total"] = stacked_bar_data.Series1 + stacked_bar_data.Series2 # Creates 'total column of two series you're interested in.
#Plot 1 - background - "total" (top) series
sns.barplot(x = stacked_bar_data.Group, y = stacked_bar_data.total, color = "blue")
#Plot 2 - overlay - "bottom" series
bottom_plot = sns.barplot(x = stacked_bar_data.Group, y = stacked_bar_data.Series1, color = "red")
topbar = plt.Rectangle((0,0),1,1,fc="red", edgecolor = 'none')
bottombar = plt.Rectangle((0,0),1,1,fc='#0000A3', edgecolor = 'none')
l = plt.legend([bottombar, topbar], ['Bottom Bar', 'Top Bar'], loc=1, ncol = 2, prop={'size':16})
l.draw_frame(False)
以上代碼摘自: http : //randyzwitch.com/creating-stacked-bar-chart-seaborn/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.