holoviz / holoviews

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

Datashading Holoviews Points Produces Empty Plots for Horizontal Graphs #4765

Open ImmaculateJSL opened 3 years ago

ImmaculateJSL commented 3 years ago

ALL software version info

Description of expected behavior and the observed behavior

When using holoviews' datashader operation on some datasets, some of the points coincidentally ended up being plotted together in a single, horizontal line. Unfortunately, the holoviews datashader operation seems to be unable to render such points while the vanilla datashader library can.

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

import holoviews as hv
import holoviews.operation.datashader as hd

# A points plot (displaying this renders the horizontal points)
points = hv.Points(data_that_produces_horizontal_points, kdims=[x_col, y_col])

# A datashaded points plot (displaying this renders an empty plot)
datashaded_points = hd.datashade(points)

Screenshots or screencasts of the bug in action

Plot Produced by Vanilla Datashader

vanilla-datashader

Plot Produced by hd.datashade

holoviews-datashade

Plot Produced by hv.Points

holoviews-points

jbednar commented 3 years ago

Damn, I thought we'd taken care of that case! There's special code for catching empty plots and all-NaN plots (where we pretty much have to make up some axes, since it's not possible to auto-range them), but this seems like a similar case we aren't yet catching.

jbednar commented 3 years ago

Hmm; actually I can't reproduce this. Works fine with or without datashade, for me using current HoloViews master (about to be released) as holoviews 1.14.1:

import pandas as pd, holoviews as hv, holoviews.operation.datashader as hd
hv.extension("bokeh")
df = pd.DataFrame(dict(x=[0,5,10],y=[0,0,0]))
points = hv.Points(df)
points

image

hd.datashade(points)

image

If that code acts differently for you, maybe update to the latest HoloViews using conda install -c pyviz/label/dev holoviews and see if that fixes it.

ImmaculateJSL commented 3 years ago

Hmmm. I've tried running your example on my machine and I'm still getting a blank datashade plot, even when switching over to the development branch. Is there anything else I could provide to maybe help you pin-point this issue?

jbednar commented 3 years ago

Hmm. Are there any errors on the JavaScript console (under More Tools/Developer Tools in Chrome)?

ImmaculateJSL commented 3 years ago

Wow; this is odd. I normally run my notebooks internally in VSCode, which is where I've noticed the issue with the datashader, but opening and running it in chrome I have no issues.

I guess for now on I'll be sure to display my plots in chrome.

VSCode Plot

vscode

Google Chrome Plot

chrome

jbednar commented 3 years ago

Hmm; that's really strange. But Datashader works in VSCode when the points aren't aligned in a row? It's hard to imagine how VSCode would enter into this interface between HoloViews and Datashader. Very mysterious!

ImmaculateJSL commented 3 years ago

Yeah, this is a strange bug for sure.

Just checked again, and anything datashaded in VSCode that isn’t a single horizontal or vertical line renders properly.

jbednar commented 3 years ago

I wonder if you're using different versions of holoviews, bokeh, or datashader when you're in VSCode compared to Jupyter...

jbednar commented 3 years ago

I've taken this issue off of the 1.14.1 milestone because that release is imminent and we aren't able to reproduce this problem yet, but once it's pinned down we can re-add it to the appropriate next release milestone.

ImmaculateJSL commented 3 years ago

I've found another odd little bug when it comes to horizontal/vertical lines when using matplotlib as my plotting extension in both Jupyter and VSCode; it appears that the datashade method is returning an empty array.

matplotlib-datashade

Conversely, using plotly as my extension actually produces the expected datashaded plots in both Jupyter and VSCode.

plotly-datashade

ImmaculateJSL commented 3 years ago

Found yet another issue; I suspect they're related, so I decided to leave it in this thread, but I can create another if need be. Note that this behavior appears to only be true when using hv.save() for horizontal/vertical plots.

The problem is that I'm trying to automate the generation and export for multiple plots derived from a given dataset. The issue is that if the image/plot I'm trying to save hasn't been displayed in the notebook, the resulting output image will be blank.

This Code Saves the Intended Horizontal Plot

import pandas as pd
import holoviews as hv
import holoviews.operation.datashader as hd

hv.extension("bokeh")
data = {
    "x": [1, 2, 3],
    "y": [0, 0, 0]
}
df = pd.DataFrame.from_dict(data)
points = hv.Points(df)
ds_points = hd.datashade(points)
ds_points
hv.save(ds_points, "test/cool.png")

Output Image

points

This Code Saves an Empty Plot

import pandas as pd
import holoviews as hv
import holoviews.operation.datashader as hd

hv.extension("bokeh")
data = {
    "x": [1, 2, 3],
    "y": [0, 0, 0]
}
df = pd.DataFrame.from_dict(data)
points = hv.Points(df)
ds_points = hd.datashade(points)
hv.save(ds_points, "test/cool.png")

Output Image

empty