散景与数百万的大数据

时间:2017-11-13 05:57:56

标签: python bokeh

我的问题是我从HIVE获得了大量数据(大约1000万点)。 Bokeh本身无法处理它。我在下面尝试使用Datashader。但是我在保存图像时遇到了问题:

import pyodbc
import pandas as pd
import datashader as ds
import datashader.transfer_functions as tf

conn = pyodbc.connect("xxxxxxxx", autocommit=True)
df = pd.read_sql("select devalue,fevalue,type from tblbigdata limit 10;",con=conn)
conn.close()

cvs = ds.Canvas(plot_width=400, plot_height=400)

agg = cvs.points(df, 'devalue', 'fevalue', ds.mean('fevalue'))
img = tf.shade(agg, cmap=['lightblue', 'darkblue'], how='log')
img.save("out.png")
print("Done")

获取错误: AttributeError: 'Image' object has no attribute 'save'

1 个答案:

答案 0 :(得分:1)

这是完整的代码。

import pyodbc
import pandas as pd
import datashader as ds
import datashader.transfer_functions as tf
from PIL import Image

conn = pyodbc.connect("xxxxxxxx", autocommit=True)
df = pd.read_sql("select devalue,fevalue,type from tblbigdata limit 10;",con=conn)
conn.close()

cvs = ds.Canvas(plot_width=400, plot_height=400)

agg = cvs.points(df, 'devalue', 'fevalue', ds.mean('fevalue'))
img = tf.shade(agg, cmap=['lightblue', 'darkblue'], how='log')
Image = img.to_pil()
Image.save("C:\MyPython\myimage123.bmp","BMP")
print("Done")