holoviz / holoviz/datashader

Duplicating the legend example with other data does not seem to work

Open
#276 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3.6k
Forks
376
Avg merge
4h 32m
Merged PRs (30d)
1

Description

I am trying to adapt the code from the [legend example notebook](https://github.com/bokeh/datashader/blob/master/examples/legends.ipynb) to another data set. I replaced the data with the 5 Gaussian distributions, updating the appropriate inputs but the legend is entirely black.

Here is the code I ran (in a jupyter notebook):
```
import pandas as pd
import numpy as np

from bokeh.io import output_notebook, show
from bokeh.plotting import Figure
output_notebook()

import datashader as ds
import datashader.transfer_functions as tf

from datashader.colors import Hot
from datashader.bokeh_ext import create_ramp_legend, create_categorical_legend

# create sample dataset
np.random.seed(1)
num=1000000

dists = {cat: pd.DataFrame(dict(x=np.random.normal(x,s,num),
y=np.random.normal(y,s,num),
val=val,cat=cat))
for x,y,s,val,cat in
[(2,2,0.01,10,"d1"), (2,-2,0.1,20,"d2"), (-2,-2,0.5,30,"d3"), (-2,2,1.0,40,"d4"), (0,0,3,50,"d5")]}

df = pd.concat(dists,ignore_index=True)
df["cat"]=df["cat"].astype("category")
df.tail() # show some of the data in an interactive setting

def create_base_plot():

# taxi data is in meters
xmin = df.x.min()
ymin = df.y.min()
xmax = df.x.max()
ymax = df.y.max()

cvs = ds.Canvas(plot_width=900,
plot_height=600,
x_range=(xmin, xmax),
y_range=(ymin, ymax))

agg = cvs.points(df, 'x', 'y')
img = tf.shade(agg, cmap=Hot, how='eq_hist')
fig = Figure(x_range=(xmin, xmax),
y_range=(ymin, ymax),
plot_width=600,
plot_height=600,
tools='')

fig.background_fill_color = 'black'
fig.toolbar_location = None
fig.axis.visible = False
fig.grid.grid_line_alpha = 0
fig.min_border_left = 0
fig.min_border_right = 0
fig.min_border_top = 0
fig.min_border_bottom = 0

fig.image_rgba(image=[img.data],
x=[xmin],
y=[ymin],
dw=[xmax-xmin],
dh=[ymax-ymin])
return fig, (xmin, ymin, xmax, ymax), agg

fig, extent, datashader_agg = create_base_plot()
show(fig)

legend_fig = create_ramp_legend(datashader_agg,
Hot,
how='eq_hist',
width=600)
show(legend_fig)
```
Here is the result:
![legend_fail](https://cloud.githubusercontent.com/assets/9484229/22521646/ac7cd4be-e886-11e6-9b22-da60c9a1f202.png)

I noticed the range for my aggregation is much larger than the taxi example, [0, 728852] compared to [0, 1968].
```
>>> datashader_agg.min()

array(0, dtype=int32)
>>> datashader_agg.max()

array(728852, dtype=int32)
```
The increased range should not be responsible for the error but I will look into that.

I am not certain this is a bug or simply an misunderstanding of the example on my part.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.