How to pass weights to a Seaborn FacetGrid

前端 未结 1 1044
滥情空心
滥情空心 2021-01-19 10:11

I have a set of data that I\'m trying to plot using a FacetGrid in seaborn. Each data point has a weight associated with it, and I want to plot a weighted histogram in each

相关标签:
1条回答
  • 2021-01-19 10:38

    You'll need to write a little wrapper function around plt.hist that accepts a vector of weights as a positional argument. Something like

    def weighted_hist(x, weights, **kwargs):
        plt.hist(x, weights=weights, **kwargs)
    
    g = sns.FacetGrid(df, ...)
    g.map(weighted_hist, "x_var", "weight_var")
    g.set_axis_labels("x_var", "count")
    
    0 讨论(0)
提交回复
热议问题