pandapower icon indicating copy to clipboard operation
pandapower copied to clipboard

Return plotly figure directly without creating an HTML file

Open jwiemer112 opened this issue 2 years ago • 6 comments

The draw_traces opens the plotly plot in a browser and returns the fig,

    if _in_ipynb():
        from plotly.offline import init_notebook_mode, iplot as plot
        init_notebook_mode()
        plot(fig, filename=filename)
    else:
        from plotly.offline import plot as plot
        plot(fig, filename=filename, auto_open=auto_open)

    return fig

I think it's better to only return the fig, so the user can decide if he want's to show the figure or just to save it.

You can just call pf_res_plotly(net, on_map=False).show(renderer="browser") for example to open the fig directly in the browser.

What do you think about it?

Greetz Janni :)

jwiemer112 avatar May 19 '22 09:05 jwiemer112

Could you please specify how this would differ from the already implemented auto_open=False which would just save the figure and not open it in the browser?

jkisse avatar May 19 '22 09:05 jkisse

auto_open -- If True, open the saved file in a web browser after saving.

Would be okay, but you can't suppress the file saving. So in every case it writes a html file: auto_open=True, a browser get's opened. =False, file get's written no browser is opened. Is quite annoying that it always writes a file...

Maybe I'm using it wrong.

vogt31337 avatar May 19 '22 09:05 vogt31337

We could just return the figure and let the user decide what to do with it, maybe that's the best solution?

jwiemer112 avatar May 19 '22 09:05 jwiemer112

For continuity in the API, I would not change the default simple_plotly behavior, but prefer another keyword argument (maybe just in **kwargs). For example, the plotly plot function (in which the file is created) has an output_type parameter that is file by default. If it is set to div, no file will be created. This parameter could be passed from the simple_plotly call all the way through to the plot() call. PRs welcome ;-)

jkisse avatar May 20 '22 09:05 jkisse

Hi @jwiemer112 I have a function which returns a pf_res_plotly figure and I need to show that figure on a PYSimpleGui canvas. When I call pf_res_plotly(net, on_map=False).show(renderer="browser") it works perfectly but I have no success showing the figure on a canvas. Do you have any suggestion? Thanks

l1358 avatar Oct 17 '22 01:10 l1358

Hey,

maybe this helps:

https://plotly.com/python/renderers/

jwiemer112 avatar Nov 01 '22 15:11 jwiemer112