简体   繁体   English

我无法使用 python 数据着色器显示图形

[英]I am not able to display graph using python datashader

I downloaded and installed datasheder using the below steps:我使用以下步骤下载并安装了 datasheder:

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

After that, I have run the code using terminal like `python data.py, but no graph is displayed;之后,我使用像`python data.py 这样的终端运行代码,但没有显示任何图形; nothin is being displayed.没有显示任何内容。

I am not sure if I've follwed the right steps here, can somebody help me display the graphs?我不确定我在这里是否遵循了正确的步骤,有人可以帮我显示图表吗? Here is my code:这是我的代码:

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)

I haven't tried your code, but there is nothing in there that would actually display the image.我没有试过你的代码,但里面没有任何东西可以实际显示图像。 Each shade() call creates an image in memory, but then nothing is done with it here.每个 shade() 调用都会在 memory 中创建一个图像,但是这里什么也没有做。 If you were in a Jupyter notebook environment and the shade() call were the last item in the cell, it would display automatically, but the regular Python prompt doesn't have such "rich display" support.如果您在 Jupyter notebook 环境中并且 shade() 调用是单元格中的最后一项,它会自动显示,但常规的 Python 提示没有这样的“丰富显示”支持。 So you can either save it to an image file on disk (using eg utils/export_image ), or you can assign the result of shade() to a variable and then pass that to a Bokeh or Matplotlib or other plot, as you prefer.因此,您可以将其保存到磁盘上的图像文件(例如使用utils/export_image ),或者您可以将 shade() 的结果分配给一个变量,然后根据需要将其传递给 Bokeh 或 Matplotlib 或其他 plot。 But you have to do something with the image if you want to see it.但是如果你想看到它,你必须对图像做些什么。

I was able to produce the plot one of the tf.shade in your code this way.我能够以这种方式在您的代码中生成 plot 之一的 tf.shade。

from datashader.utils import export_image
img = tf.shade(canvas.points(df,'x','y',agg=reductions.count()))
export_image(img=img, filename='test1', fmt=".png",  export_path=".")

This is the plot in test1.png这是test1.png中的plot Points_plot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法在 matplotlib 中显示图形 - I am not able to display graph in matplotlib 我正在使用 Dask,将 Datashader 用于 dataviz 而不是 Python 中的经典 Seaborn 有什么优势? - I am working with Dask, what are the advantages of using Datashader for the dataviz instead of the classic Seaborn in Python? 为什么我无法在 python 中使用 selenium 显示产品价格? - Why am I not able to display the product price using selenium in python? 如何使用数据着色器为图形的节点着色? - How can I color nodes of a graph, with datashader? 我无法在 python 中使用 kivy 更改屏幕 - I am not able to change the screen using kivy in python 我无法使用发布请求 python 登录网站 - I am not able to log in into a website using post requests python 我无法使用导入图像方式将图像导入python - I am not able to import an image into python using the import image way 我无法使用 python 打印图像的像素值 - i am not able to print the values of pixels of my image using python 我无法使用 python 遍历 excel 中的整行 - I am not able to loop through the whole row in excel using python 我无法使用MatplotLib生成图形以在PyQt5 App上进行绘图 - I am not able to generate a graph using MatplotLib for plotting on PyQt5 App
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM