Seaborn histplot 堆叠条未按预期堆叠 Python

Seaborn histplot stacked bar not stacking as expected in Python

我有一个 histplot 没有达到我的预期,我不确定为什么。在我的 histplot 中,我想要一个堆叠图表来比较 black_first_move 的胜利,但我得到的不是堆叠条,而是下图中的图表(并且未应用调色板)。谁能提供有关如何正确堆叠的指导?

color=['white', 'lightgrey', 'black']
black_fmr_summary_low.head(2)

sns.histplot(
    data=black_fmr_summary_low, multiple="stack",
    x="black_first_move", y="wins", hue="winner",
    palette=color) # color = ['black', 'white', 'gray'] but is not applying
plt.show()

问题是直方图聚合了未计数的数据,但您已经计算了 wins

通常条形图对计数数据更有意义,但似乎使用 weights 参数制作 is via histplot 的最简单方法:

weights (vector or key in data): If provided, weight the contribution of the corresponding data points towards the count in each bin by these factors.

sns.histplot(
    data=df,
    multiple="stack",
    x="black_first_move",
    weights="wins",  # not y="wins"
    hue="winner",
    palette=color)

带有一些最小随机数据的输出: