我使用以下步骤下载并安装了 datasheder:
git clone https://github.com/bokeh/datashader.git
cd datashader
conda install -c bokeh --file requirements.txt
python setup.py install
之后,我使用`python data.py之类的终端运行了代码,但没有显示图形;什么都没有显示。
我不确定我是否在这里遵循了正确的步骤,有人可以帮我显示图表吗?这是我的代码:
import pandas as pd
import numpy as np
import xarray as xr
import datashader as ds
import datashader.glyphs
import datashader.transfer_functions as tf
from collections import OrderedDict
np.random.seed(1)
num=10000
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()
tf.shade(ds.Canvas().points(df,'x','y'))
glyph = ds.glyphs.Point('x', 'y')
canvas = ds.Canvas(plot_width=200, plot_height=200, x_range=(-8,8)y_range=(-8,8))
from datashader import reductions
reduction = reductions.count()
from datashader.core import bypixel
agg = bypixel(df, canvas, glyph, reduction)
agg
canvas.points(df, 'x', 'y', agg=reductions.count())
tf.shade(canvas.points(df,'x','y',agg=reductions.count()))
tf.shade(canvas.points(df,'x','y',agg=reductions.any()))
tf.shade(canvas.points(df,'x','y',agg=reductions.mean('y')))
tf.shade(50-canvas.points(df,'x','y',agg=reductions.mean('val')))
agg = canvas.points(df, 'x', 'y')
tf.shade(agg.where(agg>=np.percentile(agg,99)))
tf.shade(np.sin(agg))
aggc = canvas.points(df, 'x', 'y', ds.count_cat('cat'))
aggc
tf.shade(aggc.sel(cat='d3'))
agg_d3_d5=aggc.sel(cat=['d3', 'd5']).sum(dim='cat')
tf.shade(agg_d3_d5)