has2k1 / plotnine

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

Convert a plotnine.ggplot object in a matplotlib one #637

Closed lucazav closed 1 year ago

lucazav commented 1 year ago

There are closed systems that do not allow you to create custom virtual environments or install packages other than the default ones.

In this case it'd useful to allow to convert a plotnine.ggplot object in a simple matplotlib one, so that you can:

  1. Create your plotnine.ggplot object in your personal Python environment, convert it to a matplotlib object and pickle it
  2. Upload and unpickle the object in the closed environment and plot it just using the standard matplotlib library
TyberiusPrime commented 1 year ago

I must admit, I fail to see the use case.

At that point, you might as well just store the image output. It's not like you can swap out the data (sensibly) once the plotnine object has been converted to matplotlib instructions.

You obviously can supply 'files' such as this pickle. If you can supply files, you can use pure python packages such as plotnine, by dumping their source and messing with sys.path. It's called 'vendoring'.

Now if you have policies that forbid such vendoring, but allow pickles, your policies with regards to security are likely broken.

Pickles are source-code-that-you-can-not-review.

has2k1 commented 1 year ago

This out of the scope of this project. Though you can get a matplotlib figure and if you can pickle it and unpickle it in different environments then you have a hack! And it all depends on matplotlib.

p = ggplot() + ...
fig = p.draw()
lucazav commented 1 year ago

Thank you for your feedback, guys! I'll try the path suggested by @has2k1