plotnine-examples
plotnine-examples copied to clipboard
Added plot to histogram examples
Added vlines with mean and median stat to histogram. Adding the legend is tricky, this is why I thought to include the example.
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')
)