2

I am trying to create a bar plot with labels using plotnine. According to the documentation, you can use label="stat(count)" in the aesthetic for the geom_text to print the position count for each bar. This is the equivalent of using the ..count.. keyword in ggplot2 in R.

python version is 3.6.7 plotnine version is 0.5.1

According to the documentation, this code should work:

import numpy as np
import pandas as pd
from plotnine import *
from plotnine.stats import *
from plotnine.data import mtcars

(ggplot(mtcars, aes('factor(cyl)', fill='factor(am)'))
     + geom_bar( position='fill')
     + geom_text(aes(label='stat(count)'), stat='count', position='fill')
)

When I try this I get this message: PlotnineError: "Could not evaluate the 'label' mapping: 'stat(count)' (original error: name 'stat' is not defined)

If I replace the expression label='stat(count)' with label='99' the code runs and displays a correct plot, except of course all the labels are the constant value 99 not the actual counts.

1 Answers1

0

I refreshed all my libraries and restarted the notebook server and now it works. I must have had a bad install somewhere.