ponnhide / patchworklib

Patchwork for matplotlib: A subplot manager for intuitive layouts in matplotlib, seaborn, and plotnine.
GNU General Public License v3.0
384 stars 25 forks source link

pw can't display plotnine and breaks plotnine.ggplot as a side-effect #56

Open felimomo opened 9 months ago

felimomo commented 9 months ago

In the issue that I'm encountering, two things go wrong:

  1. pw.load_ggplot() called on a ggplot object produces the following:

AttributeError: 'ggplot' object has no attribute '_create_figure'

  1. If, after attempting this, a different cell is run to display a ggplot object, the same error appears. However, ggplot objects have no problem being displayed before attempting to run pw.load_ggplot().

So it seems that the problem is a side-effect of the functionpw.load_ggplot.

Code blocks to reproduce problem

from plotnine import ggplot, aes, geom_point, scale_color_gradient
from plotnine.data import mpg

p = ggplot(aes(x="displ", y="cty"), mpg)
P = p + geom_point()
P

This displays the plot as expected.

import patchworklib as pw

No problems at import.

pw_P = pw.load_ggplot(P, figsize=(1,1))

This gives the aforementioned attribute error, with the following traceback:

----> 1 pw.load_ggplot(P, figsize=(1,1))

File [python3.10/site-packages/patchworklib/patchworklib.py:479](python3.10/site-packages/patchworklib/patchworklib.py#line=478), in load_ggplot(ggplot, figsize)
    477     matplotlib.rcParams["figure.subplot.wspace"] = figure_subplot_wspace_ori [/](workspace) figsize[0] 
    478     matplotlib.rcParams["figure.subplot.hspace"] = figure_subplot_hspace_ori [/](workspace) figsize[1] 
--> 479     fig, gcp = gcp.draw(return_ggplot=True) 
    481 else:
    482     fig, gcp = gcp.draw(return_ggplot=True)

File [/opt/venv/lib/python3.10/site-packages/patchworklib/modified_plotnine.py:37](python3.10/site-packages/patchworklib/modified_plotnine.py#line=36), in draw(self, return_ggplot, show)
     34 self._build()
     36 # setup
---> 37 figure, axs = self._create_figure()
     38 self._setup_parameters()
     39 self.theme.setup()

AttributeError: 'ggplot' object has no attribute '_create_figure'

After this, plotnine.ggplot objects start producing the same error. E.g., the following cell produces the same error

P

New ggplot objects suffer the same fate, eg.:

q = ggplot(aes(x="displ", y="cty"), mpg)
Q = q + geom_point()
Q

--> [...] AttributeError: 'ggplot' object has no attribute '_create_figure'

This was tested on a jupyterhub server. The problem only goes away if I restart the jupyterhub kernel.

turtleman99 commented 8 months ago

Solved by install an older version of plotnine

pip install git+https://github.com/has2k1/plotnine.git@v0.12.4
ponnhide commented 6 months ago

Apologies for the inconvenience. However, I am unable to continue supporting plotnine in patchworklib due to limited capacity in my labour. I believe patchworklib remains a valuable library even if it only supports matplotlib and seaborn.

If there are many requests like yours, I will consider addressing this issue, but please do not have large expectations.. I'm terribly sorry about this thing...

felimomo commented 6 months ago

No worries at all, thanks for taling a look at it anyway!

On Mon 13. May 2024 at 08:39, Hideto Mori @.***> wrote:

Apologies for the inconvenience. However, I am unable to continue supporting plotnine in patchworklib due to limited capacity in my labour. I believe patchworklib remains a valuable library even if it only supports matplotlib and seaborn.

If there are many requests like yours, I will consider addressing this issue, but please do not have large expectations.. I'm terribly sorry about this thing...

— Reply to this email directly, view it on GitHub https://github.com/ponnhide/patchworklib/issues/56#issuecomment-2108044030, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIFQIMPAPG3SQKS7QGUNJODZCDNBXAVCNFSM6AAAAABD3IAIIOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMBYGA2DIMBTGA . You are receiving this because you authored the thread.Message ID: @.***>

ponnhide commented 1 month ago

Patchworklib tentatively supports the newest version of plotnine. However, it likely still contains many bugs and may produce unexpected results. If you find anything, please let me know.

yihuanlin commented 3 weeks ago

I have the same issue in load_ggplot(ggplot, figsize) when running the script even w/o Patchworklib. It is also solved by a previous version of plotnine.