plotnine-examples icon indicating copy to clipboard operation
plotnine-examples copied to clipboard

Added plot to histogram examples

Open DataGary opened this issue 2 years ago • 1 comments

Added vlines with mean and median stat to histogram. Adding the legend is tricky, this is why I thought to include the example.

DataGary avatar Sep 09 '23 15:09 DataGary

Thank you for the contribution. If you want a legend, the right way to do it is to create a meaningful dataset. Legends / guides are created to help interpret variables and the variables are the columns of dataframe.

statistics = pd.DataFrame({
    "kind": ["mean", "median"],
    "value": [diamonds.carat.mean(), diamonds.carat.median()]
})

(
    ggplot(diamonds, aes(x='carat'))
    + geom_histogram(binwidth=0.1)
    + geom_vline(aes(xintercept="value", color="kind"), statistics, linetype='dashed', size=1)
    + labs(color='Legend')
)

has2k1 avatar Feb 27 '24 11:02 has2k1