Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blue plot #5303

Closed
hoxbro opened this issue May 10, 2022 · 11 comments
Closed

Blue plot #5303

hoxbro opened this issue May 10, 2022 · 11 comments

Comments

@hoxbro
Copy link
Member

hoxbro commented May 10, 2022

Noticed a blue plot on the holoviews documentation page here. It could be related to holoviz/datashader#1051.

image

@jbednar
Copy link
Member

jbednar commented May 10, 2022

Yes, the blue is fairly distracting here, and I think we should do the same thing we do in Datashader, which is to make a distinction between no data (zero counts show up transparent) and data (non-zero counts are mapped to the colorbar). Bokeh has options for this, but I can't seem to make them work:

import pandas as pd, numpy as np, holoviews as hv
hv.extension('bokeh')

taxi_dropoffs = {hour:arr for hour, arr in np.load('../assets/hourly_taxi_data.npz').items()}
bounds = (-74.05, 40.70, -73.90, 40.80)

image = hv.Image(taxi_dropoffs['0'], ['lon','lat'], bounds=bounds)
image.opts(width=450, tools=['hover'], clipping_colors={'NaN': 'transparent'}, colorbar=True)
image

image

image.opts(nodata=0)

image

image.data = np.where(image.data == 0, np.nan, image.data)
image

image

We'd want it to look like the last image here, but to get that to work I had to manipulate the NumPy array directly; shouldn't it work to just specify nodata?

@hoxbro
Copy link
Member Author

hoxbro commented May 10, 2022

This works without manipulating the array directly image.redim.nodata(z=0)

@jbednar
Copy link
Member

jbednar commented May 10, 2022

Thanks! @jlstevens , any idea how nodata=x is supposed to be used if not like this?

@jlstevens
Copy link
Contributor

jlstevens commented May 10, 2022

image.opts(width=450, tools=['hover'], colorbar=True, nodata=np.nan) should work as nodata is both an option on dimensions and a plot option for images. I am assuming the image has nans that need to be transparent and not zeros: just set nodata to whatever value needs to be transparent so you don't need to set clipping_colors explicitly.

@jbednar
Copy link
Member

jbednar commented May 10, 2022

The image has zeros, not nans, and nodata=np.nan fails in any case:

image

@jbednar
Copy link
Member

jbednar commented May 10, 2022

The question is how to make the zeros in the image map to NaNs; nodata=0 isn't meant to do that? The docs seem to claim that it is:

nodata:            Optional missing-data value for integer data.
                   If non-None, data with this value will be replaced with NaN so
                   that it is transparent (by default) when plotted.

@jbednar
Copy link
Member

jbednar commented May 10, 2022

Ah, that's it: the data is float32, with "0." instead of "0". I would have thought nodata would apply to floats too, but it does work if I convert to int32:

taxi_dropoffs = {hour:arr.astype('int32') for hour, arr in np.load('../assets/hourly_taxi_data.npz').items()}
...
image.opts(nodata=0)

image

It's slightly annoying that the hover shows NaN instead of 0, but I guess Bokeh is just filling with NaNs internally.

@jlstevens
Copy link
Contributor

jlstevens commented May 10, 2022

Ok, I am remembering this now...

I think we decided to focus on counts as those are integers (the main use case) and comparing floats is always tricky. I assume the floats here are due to the way the data is stored, because otherwise I would expect integers (unless this is using a mean aggregator for instance).

@jbednar
Copy link
Member

jbednar commented May 11, 2022

Right. I don't know where this data came from, but it does seem like it should have been int. Either need to fix the data, or add one of the above fixes to the notebook. Hmm.

@jbednar
Copy link
Member

jbednar commented May 17, 2022

This is fixed on http://dev.holoviews.org/getting_started/Introduction.html and should appear on the main site when the docs are rebuilt on release.

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants