0

I have some .nc data that I use xarray to analyze. I wanted to overlay a shapefile on the plot and came across hv.plot which seems to have the interactive component I have been needing. However, when I tried to plot, it does not seem to work. Then I found the following thread: Why doesn't holoviews show histogram in Spyder? but could not get Maxime's answer to work and Sander's only partly works, however I have trouble "connecting to the local host" consistently. Does anyone have a solution?

ds_path = 'Z:/MODIS-LAADS-DAAC/'
ds_file = 'anom_2016_v1.nc'

ds_anom = xr.open_dataset(ds_path+ds_file) 
x = ds_anom.Rrs_667.isel(time=0)

# create holoviews plot
hv_map = x.hvplot() 

# display graph in browser
# a bokeh server is automatically started
bokeh_server = pn.Row(hv_map).show(port=12345)

# stop the bokeh server (when needed)
bokeh_server.stop() 

However, I get this 95% of the time ERR_CONNECTION_REFUSED but occasionally get it to work and look like this (however I don't know why!!!) sample ocean data plot

IN SUMMARY:

What I want to do: https://tutorial.xarray.dev/scipy-tutorial/04_plotting_and_visualization.html#interactive-bokeh-plots-using-hvplot , https://hvplot.holoviz.org/user_guide/Geographic_Data.html#declaring-an-output-projection

What I have tried: https://discourse.holoviz.org/t/whats-the-most-efficient-way-to-overlay-a-shapefile-onto-a-hvplot-xarray-plot/397, Why doesn't holoviews show histogram in Spyder?

What I get: ERR_CONNECTION_REFUSED but occasionally (don't know why) sample ocean data plot

  • `bokeh_server.stop()` stops the server, at which point it won't accept connections, so make sure you only do that after you are done working with it. – James A. Bednar May 26 '22 at 10:53
  • hey @JamesA.Bednar - so I was able to troubleshoot the issue a little with my uni IT. If I run the code line by line it works, but as a script it has issues. I think this is attributed to what you mentioned, that `bokeh_server.stop()` is stopping it too early, before I see the connection. Do you know if there is a way to pause `bokeh_server.stop()` until I exit the window? – Cecilia Lopez-Gamundi May 26 '22 at 16:29
  • You can simply omit calling "stop", and instead kill the process using your operating system's usual tools conce you are done with it. – James A. Bednar May 28 '22 at 03:30
  • 1
    this worked! apologies for just now getting back to you. thanks @JamesA.Bednar – Cecilia Lopez-Gamundi Jul 28 '23 at 17:48

0 Answers0