holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.69k stars 402 forks source link

Scatter plot from xarray dataset fails with dynamic=False #3847

Open rjp23 opened 5 years ago

rjp23 commented 5 years ago

I'm been trying to save a simple scatter plot as a html file and with a really basic example (variable vs time) it works fine but when trying to plot variables against each other, dynamic=False stops it working.

I've tested this on an xarray test dataset so it's reproducible.

import xarray as xr
import hvplot
import hvplot.pandas
import hvplot.xarray
import geoviews as gv
import cartopy.crs as ccrs
import holoviews as hv
from holoviews import opts

air_ds = xr.tutorial.open_dataset('air_temperature').load()
<xarray.Dataset>
Dimensions:  (lat: 25, lon: 53, time: 2920)
Coordinates:
  * lat      (lat) float32 75.0 72.5 70.0 67.5 65.0 ... 25.0 22.5 20.0 17.5 15.0
  * lon      (lon) float32 200.0 202.5 205.0 207.5 ... 322.5 325.0 327.5 330.0
  * time     (time) datetime64[ns] 2013-01-01 ... 2014-12-31T18:00:00
Data variables:
    air      (time, lat, lon) float32 241.2 242.5 243.5 ... 296.49 296.19 295.69

This works perfectly:

scat = air_ds.isel(lat=0).isel(time=slice(0,10), lon=slice(0,10)).hvplot.scatter(x='time', y='air', groupby='lon', height=600, width=600, dynamic=False)

and I can either display it or save it to a HTML file

hvplot.show(scat)

hv.save(scat, 'graph.html')

However, if instead of trying to plot a scatter of a variable against a coordinate (e.g. time), I try to plot two variables against each other then I run into problems.

This works as expected still:

#create second variable based on first
air_ds['air2'] = air_ds.air + 2

#cut a smaller slice out of the dataset as don't need it to be huge to demonstrate issue
scat = air_ds.isel(lat=0).isel(time=slice(0,10), lon=slice(0,10)).hvplot.scatter(x='air2', y='air', groupby='lon', height=600, width=600)

hvplot.show(scat) #this works and shows the scatter plot with slider fine

but adding in dynamic=False then causes it to stop working:

scat = air_ds.isel(lat=0).isel(time=slice(0,10), lon=slice(0,10)).hvplot.scatter(x='air2', y='air', groupby='lon', height=600, width=600, dynamic=False)

hvplot.show(scat) #this doesn't show the plot, it's blank except for the slider
rjp23 commented 5 years ago

DataFrames don't seem to have the same issue and this work fine.

small_air_ds = air_ds.isel(lat=0).isel(time=slice(0,10), lon=slice(0,10))
df = small_air_ds.to_dataframe()
scat = df.hvplot.scatter(x='air2', y='air', groupby='lon', height=600, width=600, dynamic=False)
hv.save(scat, 'temp.html') 

I'd say this is a work-around for now but not a solution.

Edit: I take it back, this isn't working either for my more complicated example

rjp23 commented 5 years ago

@philippjfr is this definitely a bug then? I wasn't sure if I was doing something wrong. If it's a bug I'll stop trying to get it to work :-)

philippjfr commented 5 years ago

The problem here appears to be something to do with the size of the plot, if you increase it to width=900 height=900 it all works.