Simple scatter plot of xarray Datset: Not possible / bad performance
- Dominant language
- Python
- Stars
- 1.4k
- Forks
- 124
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 1
Description
This report is based/influenced by the help I got in the [Discourse forum](https://discourse.holoviz.org/t/scatter-plot-of-xarray-dataset-with-coords-one-point-to-select/5580).
I found no way to create a simple scatter plot of two `DataArray`s in an `xarray` `Dataset`. By default, only point is created, which is not a useful scatter plot. The workaround proposed above has a very poor performance and is thus not suited for a medium number of points. Interestingly, a slightly more complex scatter plot works really well: a `groupby` of one of the dimensions.
#### ALL software version info
Running Python 3.11.3 on Linux in a Jupyter Notebook in VS Code with the following packages:
```
bokeh==3.1.1
holoviews==1.16.2
hvplot==0.8.4
ipykernel==6.23.3
ipython==8.14.0
ipywidgets==8.0.6
jupyter-bokeh==3.0.7
jupyter_client==8.3.0
jupyter_core==5.3.1
jupyterlab-widgets==3.0.7
numpy==1.25.0
xarray==2023.6.0
```
(I hope I got everything that could have an influence on the result.)
#### Description, code and screenshots
Using the following `Dataset` `ds`
```python
import hvplot.xarray
import numpy as np
import xarray as xr
n = 1000
ta = xr.DataArray(
np.random.random(2*n).reshape((2, n)),
dims=("time", "x"),
coords={"time": np.arange(0,2), "x": np.arange(0, n)},
)
tsurf = xr.DataArray(
np.random.random(2*n).reshape((2, n)),
dims=("time", "x"),
coords={"time": np.arange(0,2), "x": np.arange(0, n)},
)
ds = xr.Dataset({"ta": ta, "tsurf": tsurf})
#
# Dimensions: (time: 2, x: 100)
# Coordinates:
# * time (time) int64 0 1
# * x (x) int64 0 1 2 3 4 5 6 7 8 9 10 ... 90 91 92 93 94 95 96 97 98 99
# Data variables:
# ta (time, x) float64 0.9559 0.7172 0.5907 ... 0.195 0.2481 0.3459
# tsurf (time, x) float64 0.111 0.3577 0.8058 ... 0.3501 0.7209 0.3644
```
I want to create the simplest possible scatter plot: `ta` vs `tsurf`.
```python
ds.hvplot.scatter(x="tsurf", y="ta")
```
does not work because only one point is shown:

```python
ds.hvplot.scatter(x="tsurf", y="ta", by=["time", "x"], legend=False, c="blue")
```
works by has a very poor performance. With `n=1000`, it is not usable.
Interestingly, the (from my naïve point of my) more complex plot, where we want a slider to select one of the dimensions works very well:
```python
ds.hvplot.scatter(x="tsurf", y="ta", groupby="time")
```

Note also that with coordinate informations, just dimensions, the simple scatter plot
```python
ds.hvplot.scatter(x="tsurf", y="ta")
```
works.
Contributor guide
Assessment
This issue has not been assessed yet.