holoviews: Slicing bug with xarray

I found a subtle bug when slicing Images created with xarray, where an incorrect position is returned. Unfortunately, I am unable to demonstrate this with synthetic data, but the following notebook illustrates the problem:

https://gist.github.com/drs251/f97801aa7d6f92b11c9c71c6a7c4085a

EDIT: I found out how to reproduce it: the key is that the frames have to be non-square:

import numpy as np
import xarray as xr
import holoviews as hv
hv.notebook_extension()

x = np.linspace(-3, 7, 533)
y = np.linspace(-5, 8, 894)
z = np.exp(-1*(x**2 + y[:, np.newaxis]**2))
p = np.arange(5)
zz = np.dstack([z, z, z, z, z])
array = xr.DataArray(zz, coords=[y, x, p], dims=['x', 'y', 'p'])
array.name = "intensity"

image = hv.Dataset(array).to(hv.Image, kdims=["x", "y"])
image[0, -1:1, -1:1]

The slice should be nicely centered on the maximum, but it’s not.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 36 (36 by maintainers)

Most upvoted comments

Great you figured it out!

Sorry for all the problems I caused. Totally my mistake.

No, I’d say that’s a real issue and as you show for xarray we should ignore the matplotlibrc and specify an explicit origin. If you’re up for contributing, adding an explicit origin=‘upper’ here https://github.com/ioam/holoviews/blob/master/holoviews/plotting/mpl/raster.py#L160 would be appreciated otherwise I’ll try to get around to it soon.