dstl / Stone-Soup

A software project to provide the target tracking community with a framework for the development and testing of tracking algorithms.
https://stonesoup.rtfd.io
MIT License
400 stars 131 forks source link

Plotter & Plotterly figures do not display automatically when scripts/functions are ran from the command line/IDE #739

Open gawebb-dstl opened 1 year ago

gawebb-dstl commented 1 year ago

Figures from the Plotter and Plotterly class don't automatically appear when the scripts are ran in Pycharm or the command line. I expect they won't display when ran from other IDEs.

For each the figures can made to display: For the Plotterly class using: plotter.fig.show() instead of plotter.fig makes the figures appear. However using plotter.fig.show() in the tutorials breaks the Sphinx docs. For the Plotter class, plt.show() is needed at the end of the script to force the figures to appear.

I feel this behaviour could trip up people who are new to Stone-Soup when they try to run the tutorials or examples

khurramkhalil commented 1 year ago

Not exactly similar but if someone is using Spyder (IDE bundled with Anaconda), even adding plt.show() doesn't render figures. You need to manually change the default spyder renderer to browser by first importing import plotly.io as pio and then setting renderer to the browser by pio.renderers.default ='browser'.

cntaylor commented 1 year ago

I believe this is a (somewhat) known problem with plot.ly (which Plotterly is using internally). For example, see these links (generally in decreasing order of usefulness)

Basically, it sounds like plotly opens up a web server but for some reason that web server sometimes gets shut down before the web browser accesses it. Solutions are to either (a) run things in a Jupyter notebook or (2) use plotter.fig.write_html('desired_filename.html') and then click on the .html file.

What we have started doing is calling write_html followed by show(). About 50% of the time, show works, so no problem. When it doesn't work, we double-click on the generated html file and it opens up in the browser without a problem.