2016-05-26 10 views
-2

私はいくつかの量的変数を持つバイナリ分類プロジェクトに取り組んでいます。私は探索的分析段階で以下のようなヒストグラムをプロットしたいと思います。しかし、2日間オンラインで調査したところ、私はまだPythonで解決策を見つけることができました。Pythonでバイナリカラーヒストグラムをプロットする方法は?

Rでは、私は1行のコードでそれをどのように知っていますか:ggplot(train, aes(var_x, fill = var_y))。 Pythonでは誰も私にmatplotlibやseabornと同等の構文を教えることができますか?

enter image description here

+0

を試してみましたか? – mwaskom

+0

[* matplotlib *で2つのヒストグラムを同時にプロットする](http://stackoverflow.com/questions/6871201/plot-two-histograms-at-the-same-time-with-matplotlib) – Schorsch

答えて

-1

seabornにそのようなオーバーレイバーグラフを得るためにそれはあなたが実際には二つのプロット、「背景」のための1つを作成する必要がR.

から1行のコードよりも少し複雑ですし、上記のコードは、から取られた

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) 

を '前景' の1:あなたは `plt.hist`をhttp://randyzwitch.com/creating-stacked-bar-chart-seaborn/

関連する問題