我无法使用python数据共享器显示图形

时间:2016-12-08 06:28:01

标签: python data-visualization bokeh datashader

我使用以下步骤下载并安装了数据管理器:

git clone https://github.com/bokeh/datashader.git  
cd datashader  
conda install -c bokeh --file requirements.txt  
python setup.py install

之后,我使用`python data.py这样的终端运行代码,但是没有显示图表; nothin正在展示。

我不确定我是否在这里采取了正确的步骤,有人可以帮助我显示图表吗?这是我的代码:

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)

1 个答案:

答案 0 :(得分:2)

我还没有尝试过您的代码,但实际上没有任何内容可以显示图像。每个shade()调用在内存中创建一个图像,但这里没有任何操作。如果你在Jupyter笔记本环境中并且shade()调用是单元格中的最后一项,它将自动显示,但常规的Python提示没有这样的"丰富的显示"支持。因此,您可以将其保存到磁盘上的图像文件中(使用例如utils/export_image),或者您可以将shade()的结果分配给变量,然后将其传递给Bokeh或Matplotlib或其他绘图,就像您一样喜欢。但如果你想看到它,你必须对图像做些什么。