I created a plot in the following way:
import os
import pickle
import pandas as pd
from plotnine import (
options, theme_tufte, ggplot, aes, geom_bar,
geom_text, after_stat, labs
)
dataset_url = 'http://bit.ly/titanic-dataset-csv'
df = pd.read_csv(dataset_url)
options.dpi = 300
p = (
ggplot(df)
+ aes(x='Pclass', fill="factor(Pclass)")
+ geom_bar()
+ geom_text(
aes(label = after_stat('count')),
stat = 'count',
nudge_x = -0.14,
nudge_y = 0.125,
va = 'bottom',
size = 8
)
+ geom_text(
aes(label = after_stat('prop*100'), group=1),
stat = 'count',
nudge_x = 0.14,
nudge_y = 0.125,
va = 'bottom',
format_string = '({:.1f}%)',
size = 8
)
+ labs(title='Passenger Count by Class',
x='Class', y='Count', fill='Class')
+ theme_tufte()
)
Now I'm trying to pickle the related Matplotlib figure as follows:
mplt = p.draw()
project_folder = r'<my-folder>'
pickle.dump( mplt, open(os.path.join(project_folder, "mplt.pkl"), "wb") )
But I'm getting the following error:
NotImplementedError: Sorry, pickling not yet supported. See pydata/patsy#26 if you want to help.
I tried to pickle a plot generated directly with Matplotlib and everything works fine.
What's wrong with the Matplotlib figure given by the ggplot draw() method?