我想在python 3中重新創建這個密度圖:math.stackexchange.com/questions/845424/the-expected-outcome-of-a -random-遊戲的棋在同一圖上繪製多個密度曲線:在Python 3中對子集類別進行加權
End Goal: I need my density plot to look like this
藍色曲線下面積等於紅色,綠色,紫色曲線相結合的,因爲不同的結果(繪圖,黑勝,和白色勝利)是總數(全部)的子集。
我該如何讓python實現並相應地繪製它?
這裏是1000模擬pastebin.com/YDVMx2DL
from matplotlib import pyplot as plt
import seaborn as sns
black = results_df.loc[results_df['outcome'] == 'Black']
white = results_df.loc[results_df['outcome'] == 'White']
draw = results_df.loc[results_df['outcome'] == 'Draw']
win = results_df.loc[results_df['outcome'] != 'Draw']
Total = len(results_df.index)
Wins = len(win.index)
PercentBlack = "Black Wins ≈ %s" %('{0:.2%}'.format(len(black.index)/Total))
PercentWhite = "White Wins ≈ %s" %('{0:.2%}'.format(len(white.index)/Total))
PercentDraw = "Draw ≈ %s" %('{0:.2%}'.format(len(draw.index)/Total))
AllTitle = 'Distribution of Moves by All Outcomes (nSample = %s)' %(workers)
sns.distplot(results_df.moves, hist=False, label = "All")
sns.distplot(black.moves, hist=False, label=PercentBlack)
sns.distplot(white.moves, hist=False, label=PercentWhite)
sns.distplot(draw.moves, hist=False, label=PercentDraw)
plt.title(AllTitle)
plt.ylabel('Density')
plt.xlabel('Number of Moves')
plt.legend()
plt.show()
後results_df的.csv文件上面代碼沒有重量密度曲線,這是我真的需要想出如何生成密度曲線的權重因此以及保存我的標籤圖例
density curves, no weights; help
我也試過頻率直方圖,即按比例分配高度正確,但我寧願保持4條曲線重疊在一起,以獲得「更乾淨」的外觀... 我不喜歡這個頻率圖,但這是我目前的修復。
results_df.moves.hist(alpha=0.4, bins=range(0, 700, 10), label = "All")
draw.moves.hist(alpha=0.4, bins=range(0, 700, 10), label = PercentDraw)
white.moves.hist(alpha=0.4, bins=range(0, 700, 10), label = PercentWhite)
black.moves.hist(alpha=0.4, bins=range(0, 700, 10), label = PercentBlack)
plt.title(AllTitle)
plt.ylabel('Frequency')
plt.xlabel('Number of Moves')
plt.legend()
plt.show()
如果與正確子集的權重4條密度曲線輸出第一情節以及保留了自定義圖例,顯示百分比任何人都可以寫蟒3代碼,這將不勝感激。
一旦密度曲線與正確的子集的權重繪製的,我也有興趣在Python 3代碼找到每個密度曲線的最高點座標顯示的移動最高頻率,一旦我將其放大至50萬迭代。
謝謝