获取< script>和< div>使用Python的Plotly标签 [英] Getting <script> and <div> tags from Plotly using Python
问题描述
我想知道是否有人知道一个好方法(最好是内置方法,但我可以自己编写自己的方法)来获取< script>
和< div>
标签。
我已经很熟悉与散景,并真正享受使用它的二维可视化,但真正想要整合Plotly以及其三维可视化功能。
让我知道您是否需要有关该项目的任何额外细节。
如果您打电话:
plotly.offline.plot(data,filename ='file.html')
它创建一个名为 file.html
的文件并将其打开在你的网页浏览器中。但是,如果您这样做:
plotly.offline.plot(data,include_plotlyjs = False,output_type ='div')
调用将返回一个只有创建图表所需div的字符串,您可以将其存储在任何变量中你希望(而不是磁盘)。
我刚刚尝试过它,它返回了,我正在做一个给定的图表:
< div id =82072c0d-ba8d-4e86-b000-0892be065ca8style =height:100%; width:100%;类= plotly-图表-DIV >< / DIV>
< script type =text / javascript> window.PLOTLYENV = window.PLOTLYENV || {}; window.PLOTLYENV.BASE_URL =https://plot.ly; Plotly.newPlot(82072c0d-ba8d-4e86-b000-0892be065ca8,
[{y:..bunch of data ...,x:..Lots of data ..,{showlegend:true,title:title,xaxis:{zeroline:true,showline:true},
yaxis:{zeroline:true,showline:true,range:[0,22.63852380952382]}},{linkText:导出到plot.ly,showLink:真})< /脚本>
请注意,它只是您应该嵌入更大页面的html的一小部分。为此,我使用了一个像Jinga2这样的标准模板引擎。
通过这个,你可以创建一个html页面,其中几个图表以你想要的方式排列,甚至可以将它作为服务器对ajax调用的响应,非常好。
更新:
请记住,您需要包含所有这些图表的标准js文件才能正常工作。
您可以包含< script src =https://cdn.plot.ly/plotly-latest.min.js> < / script>
在放置div之前。如果你把这个js放在页面的底部,这些图表将不起作用。
I was wondering if anyone knew a good way (preferably a built in method, but I'm open to writing my own of course) to get the <script>
and <div>
tags from the HTML output of the Plotly offline client.
I'm already familiar with bokeh and really enjoy using it for 2D visualization, but would really like to integrate Plotly as well for its 3D visualization capabilities.
Let me know if you need any extra details about the project.
If you call:
plotly.offline.plot(data, filename='file.html')
It creates a file named file.html
and opens it up in your web browser. However, if you do:
plotly.offline.plot(data, include_plotlyjs=False, output_type='div')
the call will return a string with only the div required to create the chart, which you can store in whatever variable you desire (and not to disk).
I just tried it and it returned, for a given chart that I was doing:
<div id="82072c0d-ba8d-4e86-b000-0892be065ca8" style="height: 100%; width: 100%;" class="plotly-graph-div"></div>
<script type="text/javascript">window.PLOTLYENV=window.PLOTLYENV || {};window.PLOTLYENV.BASE_URL="https://plot.ly";Plotly.newPlot("82072c0d-ba8d-4e86-b000-0892be065ca8",
[{"y": ..bunch of data..., "x": ..lots of data.., {"showlegend": true, "title": "the title", "xaxis": {"zeroline": true, "showline": true},
"yaxis": {"zeroline": true, "showline": true, "range": [0, 22.63852380952382]}}, {"linkText": "Export to plot.ly", "showLink": true})</script>
Notice how its just a tiny portion of an html that you are supposed to embed in a bigger page. For that I use a standard template engine like Jinga2.
With this you can create one html page with several charts arranged the way you want, and even return it as a server response to an ajax call, pretty sweet.
Update:
Remember that you'll need to include the plotly js file for all these charts to work.
You could include <script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
just before putting the div you got. If you put this js at the bottom of the page, the charts won't work.
这篇关于获取< script>和< div>使用Python的Plotly标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!