org-arl / arlpy

ARL Python Tools
BSD 3-Clause "New" or "Revised" License
118 stars 37 forks source link

Plotting issues on Spyder #65

Closed kerentalmon closed 3 years ago

kerentalmon commented 3 years ago

a. Running great on jupyter notebook but not plotting on other IDE e.g. Spyder b. Plots saving format - cannot save into PDF

mchitre commented 3 years ago

Plots in arlpy are made using Bokeh, so you might want to check whether your Spyder install works with Bokeh.

kerentalmon commented 3 years ago

Bokeh displays on IPython. To use on IDE such as Spyder, the plotting commands has to be rerun on the interactive console and then web-browser opens to display the plots

mchitre commented 3 years ago

So doing that resolves the problem for you?

kerentalmon commented 3 years ago

The above solution is kind of a makeshift and may not be complete. For my needs I updated (on my machine) arlpy plot.py script as follows: in class figure: under def __enter__(self): I added the following

         _bplt.output_file(filename="custom_filename.html")  # temp name for the figure
        p = _figure  
        _bplt.save(p)  # save the figure
        webbrowser.open('custom_filename.html')  # display in browser

at the top I added import webbrowser

I did not check for conflicts with jupyter notebook. The added code saves any figure as temporary file (using bokeh) and later shows it in the default computer browser. I did not implement it in class many_figures: and cannot ascertain there isn't other issues that might arise.

I guess a better way will be to implement it in thetry exceptpart in the beginning of the script where usage of IPython is checked.

mchitre commented 3 years ago

Seems like a reasonable workaround for your needs, and we'll leave it here in case someone else needs it.

I believe this is currently being addressed by Spyder team in https://github.com/spyder-ide/spyder/issues/8367, and when that issue is closed, Spyder should work with Bokeh plots (and therefore automatically with arlpy plots). So no further action required here.