Closed lucazav closed 9 months ago
@has2k1 I installed the developer version of plotnine in my conda environment on Windows using:
pip install "plotnine @ https://github.com/has2k1/plotnine/archive/master.zip"
Then I tried the upon code and I'm getting the following error:
cannot pickle 'KeyedRef' object
Is there anything wrong in my installation?
This works for me.
from plotnine import *
from plotnine.data import mtcars
def test_pickle(obj):
import io
import pickle
with io.BytesIO() as f:
pickle.dump(obj, f)
f.seek(0)
unpickled_obj = pickle.load(f)
return unpickled_obj
p = (
ggplot(mtcars, aes("wt", "mpg"))
+ geom_point()
)
fig = p.draw()
test_pickle(fig)
test_pickle(p)
My fault, I was using dill
instead of pickle
. Now it's working like a charm with pickle
.
I created a plot in the following way:
Now I'm trying to pickle the related Matplotlib figure as follows:
But I'm getting the following error:
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?