has2k1 / plotnine

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

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

Open fkgruber opened 3 weeks ago

fkgruber commented 3 weeks ago

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 commented 3 weeks ago

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

has2k1 commented 2 weeks ago

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.