首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在数据库上使用HoloViews / hvPlot

如何在数据库上使用HoloViews / hvPlot
EN

Stack Overflow用户
提问于 2020-04-24 02:47:20
回答 3查看 553关注 0票数 2

如何让HoloViews图或Hvplot在数据库上工作?

生成的图也应该保持所有的交互性。

EN

回答 3

Stack Overflow用户

发布于 2020-05-11 07:07:14

Bokeh file_html将返回HTML+JS代码,以提供数据的交互式绘图。HTML总大小必须小于20MB。您的数据需要内联到您的HTML,否则您可能会遇到CSRF错误。确保您已经安装了python holoviewsbokehhvplot包。示例:

代码语言:javascript
运行
复制
import math
import numpy as np
import pandas as pd
import holoviews as hv
from bokeh.embed import components, file_html
from bokeh.resources import CDN

hv.extension('bokeh')

import hvplot

renderer = hv.renderer('bokeh').instance(fig='html', holomap='auto')

# see https://github.com/ioam/holoviews/issues/1819
def displayHoloviews(hv_plot, html_name="plot.html", width=1000, height=600, renderer=renderer):
  plot = renderer.get_plot(hv_plot).state
  setattr(plot, 'plot_width', width)
  setattr(plot, 'plot_height', height)
  displayHTML(file_html(plot, CDN, html_name))

index = pd.date_range('1/1/2000', periods=1000)
df = pd.DataFrame(np.random.randn(1000, 4), index=index, columns=list('ABCD')).cumsum()

displayHoloviews(hvplot.hvPlot(df).line(y=['A','B','C','D']))

Four Random Walk Lines plotted and interactive

票数 4
EN

Stack Overflow用户

发布于 2020-04-24 02:47:20

您可以使用将HoloViews绘图另存为displayHTML文件,然后使用displayHTML()

解决方案的灵感来自于这个博客:

https://anitagraser.com/2020/02/02/first-working-movingpandas-setup-on-databricks/

下面是一个工作示例

代码语言:javascript
运行
复制
# import libraries
import numpy as np
import pandas as pd

import holoviews as hv
import hvplot.pandas

# create sample date
df = pd.DataFrame(np.random.rand(50, 2), columns=['col1', 'col2'])
df['col3'] = np.random.randint(0, 2, 50)

# create holoviews scatter plot
hv_scatter = df.hvplot(kind='scatter', x='col1', y='col2', groupby='col3')

# save scatter plot as html
hv.save(hv_scatter, 'hv_scatter.html')

# assign html file to variable
with open('hv_scatter.html', 'r') as html_file:
  html_scatter = html_file.read()

# display scatter plot
displayHTML(html_scatter)

作为替代方案,您也可以将您的绘图呈现为Bokeh绘图,然后使用此笔记本的示例:

https://docs.databricks.com/notebooks/visualizations/bokeh.html

票数 2
EN

Stack Overflow用户

发布于 2021-04-20 18:29:20

您可以简单地使用

代码语言:javascript
运行
复制
import holoviews as hv

your_plot = hv.Points(np.random.multivariate_normal((0,0), [[0.1, 0.1], [0.1, 1.0]], (1000,)))

renderer = hv.renderer("bokeh")
displayHTML(renderer.html(your_plot))

但是,使用displayHTML()的AFAIU会阻止decimate()datashaderscalability features,它将只显示绘图的初始渲染版本。其他答案也是如此,我不确定当前是否存在在DataBricks上保持可伸缩性的解决方案(我对这样的解决方案 非常感兴趣!)。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61394775

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档