has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
4.07k stars 225 forks source link

Cache issue in Jupyter Notebooks? #579

Closed thistlillo closed 2 years ago

thistlillo commented 2 years ago

I am trying to build a plot using plotnine in a Jupyeter Notebook running on a remote Jupyter server, linux machine. As dev tool I am using Visual Studio code, the libraries are installed in a conda environment.

The plot I am trying to build is:

from plotnine import *
import pandas as pd
x = [1, 2, 3, 4, 5]
y = [100, 50, 313, 232, 12]
df = pd.DataFrame.from_dict( dict(x=x, y=y) )
display(df)
( ggplot(data=df,
        mapping=aes(x=x, y=y))
        + geom_bar()
        + theme(text=element_text(size=12, family="Century Schoolbook")) + theme_bw()
        + ggtitle("Count")
)

But it gives me this error:

['stat_count() must not be used with a y aesthetic']()

There was a stat_count() from the code I copied from a previous chart, but, as you can see, I removed it. However, it seems that someone in the pipeline did not realize I deleted it. I do not know if it is plotnine or other libraries.

I am also having problems with fonts: plotnine (and involved libraries) did not realize I have installed some Serif fonts it used not to find. It keeps using a Sans-Serif font in the charts even if I specify a Serif family or a specific font. Before I installed the serif fonts, the library gave me some warnings about fonts not found. Now there are no warnings, but the fonts in the plots are always the sans-serif default one.

I tried to kill/restart the kernel/visual studio code, but the issue did not go away. Using:

plotnine=0.8.0
python 3.8.6
Version: 1.65.2 (user setup)
Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
Date: 2022-03-10T14:33:55.248Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043
has2k1 commented 2 years ago

The issue is mapping=aes(x=x, y=y)) should be mapping=aes(x='x')).

Also, to avoid other surprises make sure you are mapping to the columns 'x' in the dataframe and not the x value in the environment.

For the fonts, plotnine relies entirely on the backend (Matplotlib) to use the available fonts and if the fonts are installed properly and referred to accurately there should not be a problem.