pandapower
pandapower copied to clipboard
Return plotly figure directly without creating an HTML file
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 :)
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?
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.
We could just return the figure and let the user decide what to do with it, maybe that's the best solution?
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 ;-)
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
Hey,
maybe this helps:
https://plotly.com/python/renderers/