holoviz / holoviews

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

QuadMesh plots made-up data, when it is named 'top'. #4747

Open nitrocalcite opened 3 years ago

nitrocalcite commented 3 years ago

Description of expected behavior and the observed behavior

When I use hv.QuadMesh to plot an xarray dataset with a field named "top", it seemingly makes up its own data. I expect to see my data. hv.Image doesn't show this behavior. Changing the field name to anything else results in the usual behavior.

Screenshots or screencasts of the bug in action

image

Complete, minimal, self-contained example code that reproduces the issue

import xarray as xr
import numpy as np
import holoviews as hv
hv.extension('bokeh')

arr = np.random.rand(7,8)
ds_top = xr.Dataset({
    'top': (('ard', 'issab'), arr)
}, coords={
    'ard': np.arange(7),
    'issab': np.array([4,6,8,10,12,15,20,25])
})

ds_data = xr.Dataset({
    'data': (('ard', 'issab'), arr)
}, coords={
    'ard': np.arange(7),
    'issab': np.array([4,6,8,10,12,15,20,25])
})

# differing results (do not have to be in a Layout; just so they are easy to compare)
hv.QuadMesh(ds_top['top']) + hv.QuadMesh(ds_data['data']) + hv.Image(ds_top['top']) + hv.Image(ds_data['data'])

The first one, hv.QuadMesh(ds_top['top']), is all black, while the others plot correctly. If you enable the hovertool, .opts(tools=['hover']), you'll notice that hv.QuadMesh(ds_top['top']) gives different numbers than the rest of the plots, despite the scale being set correctly; that's why it's all black. It's not clear to me where these numbers come from.

Note that ds_top['top'] evaluates to an xs.DataArray named top, whereas ds_data['data'] has the same name but is named data. As far as I can tell, that's the only difference. Either way, all four of these graphs should be showing the same data.

ALL software version info

bokeh 2.2.3 holoviews 1.13.5 notebook 6.1.5 Windows 10/Chrome & Firefox

I did a quick search for "top" in the Holoviews codebase but didn't see anything particularly notable. This seems pretty bizarre...can anyone else reproduce? A workaround is to simply not name anything 'top'. Please let me know if I'm missing something embarrassingly obvious. Thanks!

poplarShift commented 3 years ago

Interesting! The reason seems to be bokeh, not holoviews. Check out the following where I replaced top by left:

import xarray as xr
import numpy as np
import holoviews as hv
hv.extension('bokeh')

arr = np.random.rand(7,8)
ds_top = xr.Dataset({
    'left': (('ard', 'issab'), arr)
}, coords={
    'ard': np.arange(7),
    'issab': np.array([4,6,8,10,12,15,20,25])
})

ds_data = xr.Dataset({
    'data': (('ard', 'issab'), arr)
}, coords={
    'ard': np.arange(7),
    'issab': np.array([4,6,8,10,12,15,20,25])
})

# differing results (do not have to be in a Layout; just so they are easy to compare)
l = hv.QuadMesh(ds_top['left']) + hv.QuadMesh(ds_data['data']) + hv.Image(ds_top['left']) + hv.Image(ds_data['data'])
l.apply.opts(tools=['hover'])

The reason seems to be how bokeh's Quad glyphs are defined:

source = ColumnDataSource(dict(
        left=foo,
        top=bar,
        right=baz,
        bottom=bonk,
    )
)

Would have to see in the holoviews codebase if one can easily avoid these namespace clashes.