plotnine icon indicating copy to clipboard operation
plotnine copied to clipboard

Added argument in show() to speficy figure number to use

Open fkgruber opened this issue 1 year ago • 3 comments

I added a feature allow to select the figure number to use to plot. This way you can work simultaneously with 2 different plot displayed in 2 different figure windows.

Example usage


import plotnine as pn
import pandas as pd

ggp1=(
     pn.ggplot(pd.DataFrame(
         {"x":[1,2,3,4,5],
          "y":[4,3,4,3,3]}),
               pn.aes("x","y")
               )
     +pn.geom_point()
    )
ggp1.show(1)



ggp2=(
    pn.ggplot(pd.DataFrame({"x":[1,2,3,4,5],
                            "y":[4,3,4,3,3]}),
              pn.aes("x","y"))
    +pn.geom_point(color="red")
)
ggp2.show(2)


(ggp1+pn.geom_line(color='blue')).show(1) 

fkgruber avatar Jun 13 '24 14:06 fkgruber

I push one more change to clear the figure when you provide a figure number.

fkgruber avatar Jun 17 '24 04:06 fkgruber

Thanks for this feature. I am not yet sure about the internal API changes. The external API p.show(num=1) is fine okay, but we should find a way not to add the parameter to 4 other internal functions i.e.

ggplot.draw(bool=False, num=None)
facet.setup(num=None)
facet.make_figure(num=None)
facet._make_figure(num=None)

I will find a way to get this in before the next release.

has2k1 avatar Jun 24 '24 12:06 has2k1

Out of precaution because the API may change, I will look to add reusing figures as part of v0.15.0 instead of v0.14.0 which is the next one. v0.15.0 will do more things around figures.

Other options to consider for this functionality are:

ggplot(figure_num=1)
from plotnine.options import set_option
set_option(figure_num=1)
...

has2k1 avatar Aug 01 '24 12:08 has2k1

Hi Is there a branch for 0.15 that implements this feature? Would love to try

fkgruber avatar Mar 31 '25 20:03 fkgruber