相当于 D3.js 的 Python
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12977517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python equivalent of D3.js
提问by Eiyrioü von Kauyf
Can anyone recommend a Python library that can do interactivegraph visualization?
谁能推荐一个可以进行交互式图形可视化的 Python 库?
I specifically want something like d3.jsbut for pythonand ideally it would be 3D as well.
我特别想要像d3.js这样的东西,但python理想情况下它也是 3D 的。
I have looked at:
我看过:
- NetworkX- it only does
Matplotlibplots and those seem to be 2D. I didn't see any sort of interactiveness, like one thatd3.jsgives, such as pulling nodes around. - graph-tool- it does only 2D plots and has very slow interactivegraphs.
回答by juniper-
See:
看:
Is there a good interactive 3D graph library out there?
The accepted answer suggests the following program, which apparently has python bindings: http://ubietylab.net/ubigraph/
接受的答案表明以下程序,它显然具有 python 绑定:http: //ubietylab.net/ubigraph/
Edit
编辑
I'm not sure about the interactivity of NetworkX, but you can definitely make 3D graphs. There is at least one example in the gallery:
我不确定 NetworkX 的交互性,但您绝对可以制作 3D 图形。图库中至少有一个例子:
http://networkx.lanl.gov/examples/drawing/edge_colormap.html
http://networkx.lanl.gov/examples/drawing/edge_colormap.html
And another example in the 'examples'. This one, however, requires that you have Mayavi.
“示例”中的另一个示例。但是,这需要您拥有 Mayavi。
http://networkx.lanl.gov/examples/3d_drawing/mayavi2_spring.html
http://networkx.lanl.gov/examples/3d_drawing/mayavi2_spring.html
回答by Aric
There is an interesting port of NetworkX to Javascript that might do what you want. See http://felix-kling.de/JSNetworkX/
有一个有趣的 NetworkX 移植到 Javascript 可能会做你想做的事。见http://felix-kling.de/JSNetworkX/
回答by Vincent Agnus
You could use d3pya python module that generate xml pages embedding d3.js script. For example :
您可以使用d3py一个生成嵌入 d3.js 脚本的 xml 页面的 python 模块。例如 :
import d3py
import networkx as nx
import logging
logging.basicConfig(level=logging.DEBUG)
G = nx.Graph()
G.add_edge(1,2)
G.add_edge(1,3)
G.add_edge(3,2)
G.add_edge(3,4)
G.add_edge(4,2)
# use 'with' if you are writing a script and want to serve this up forever
with d3py.NetworkXFigure(G, width=500, height=500) as p:
p += d3py.ForceLayout()
p.show()
回答by psychemedia
One recipe that I have used (described here: Co-Director Network Data Files in GEXF and JSON from OpenCorporates Data via Scraperwiki and networkx) runs as follows:
我使用过的一个方法(此处描述:来自 OpenCorporates Data via Scraperwiki 和 networkx 的 GEXF 和 JSON 中的 Co-Director Network Data Files)运行如下:
- generate a network representation using networkx
- export the network as a JSON file
- import that JSON into to d3.js. (networkxcan export both the tree and graph/network representations that d3.jscan import).
- 使用networkx生成网络表示
- 将网络导出为 JSON 文件
- 将该 JSON 导入到d3.js 中。(networkx可以导出d3.js可以导入的树和图形/网络表示)。
The networkxJSON exportertakes the form:
该networkxJSON出口国采取以下形式:
from networkx.readwrite import json_graph
import json
print json.dumps(json_graph.node_link_data(G))
Alternatively you can export the networkas a GEXFXML file and then import this representation into the sigma.jsJavascript visualisation library.
或者,您可以将网络导出为GEXFXML 文件,然后将此表示导入sigma.jsJavascript 可视化库。
from xml.etree.cElementTree import tostring
writer=gf.GEXFWriter(encoding='utf-8',prettyprint=True,version='1.1draft')
writer.add_graph(G)
print tostring(writer.xml)
回答by richie
Check out python-nvd3. It is a python wrapper for nvd3. Looks cooler than d3.py and also has more chart options.
查看python-nvd3。它是 nvd3 的 python 包装器。看起来比 d3.py 更酷,并且还有更多的图表选项。
回答by sk8asd123
Have you looked at vincent? Vincent takes Python data objects and converts them to Vega visualization grammar. Vega is a higher-level visualization tool built on top of D3. As compared to D3py, the vincent repo has been updated more recently. Though the examples are all static D3.
你看过文森特吗?Vincent 将 Python 数据对象转换为 Vega 可视化语法。Vega 是一个建立在 D3 之上的更高级别的可视化工具。与 D3py 相比,vincent repo 最近更新了。尽管示例都是静态的 D3。
more info:
更多信息:
The graphs can be viewed in Ipython, just add this code
可以在Ipython中查看图形,只需添加此代码
vincent.core.initialize_notebook()
Or output to JSON where you can view the JSON output graph in the Vega online editor (http://trifacta.github.io/vega/editor/) or view them on your Python server locally. More info on viewing can be found in the pypi link above.
或者输出到 JSON,您可以在 Vega 在线编辑器 ( http://trifacta.github.io/vega/editor/) 中查看JSON 输出图,或者在本地的 Python 服务器上查看它们。有关查看的更多信息可以在上面的 pypi 链接中找到。
Not sure when, but the Pandas package should have D3 integration at some point. http://pandas.pydata.org/developers.html
不确定何时,但 Pandas 包应该在某个时候集成 D3。 http://pandas.pydata.org/developers.html
Bokeh is a Python visualization library that supports interactive visualization. Its primary output backend is HTML5 Canvas and uses client/server model.
Bokeh 是一个 Python 可视化库,支持交互式可视化。它的主要输出后端是 HTML5 Canvas 并使用客户端/服务器模型。
examples: http://continuumio.github.io/bokehjs/
回答by Mateo Sanchez
Plotly supports interactive 2D and 3D graphing. Graphs are rendered with D3.js and can be created with a Python API, matplotlib, ggplot for Python, Seaborn, prettyplotlib, and pandas. You can zoom, pan, toggle traces on and off, and see data on the hover. Plots can be embedded in HTML, apps, dashboards, and IPython Notebooks. Below is a temperature graphshowing interactivity. See the gallery of IPython Notebookstutorialsfor more examples.
Plotly 支持交互式 2D 和 3D 绘图。图形使用 D3.js 呈现,并且可以使用Python API、matplotlib、ggplot for Python、Seaborn、prettyplotlib和pandas 创建。您可以缩放、平移、打开和关闭跟踪,并在悬停时查看数据。绘图可以嵌入到 HTML、应用程序、仪表板和 IPython 笔记本中。下面是显示交互性的温度图。有关更多示例,请参阅IPython Notebooks教程库。


The docsprovides examples of supported plot types and code snippets.
该文档提供了支持的图形类型和代码段的例子。

Specifically to your question, you can also make interactive plotsfrom NetworkX.

For 3D plotting with Python, you can make 3D scatter, line, and surface plots that are similarly interactive. Plots are rendered with WebGL. For example, see a 3D graphof UK Swap rates.

具体到您的问题,您还可以从 NetworkX制作交互式绘图。

对于使用 Python 进行 3D 绘图,您可以制作具有类似交互性的 3D 散点图、线图和曲面图。绘图是用 WebGL 渲染的。例如,查看英国掉期利率的 3D 图表。


Disclosure: I'm on the Plotly team.
披露:我在 Plotly 团队。
回答by Ram
I would suggest using mpld3 which combines D3js javascript visualizations with matplotlib of python.
我建议使用 mpld3,它将 D3js javascript 可视化与 python 的 matplotlib 结合起来。
The installation and usage is really simple and it has some cool plugins and interactive stuffs.
安装和使用非常简单,它有一些很酷的插件和互动的东西。
回答by Wes
For those who recommended pyd3, it is no longer under active development and points you to vincent. vincent is also no longer under active development and recommends using altair.
对于那些推荐pyd3 的人,它不再处于积极开发阶段,而是将您指向vincent。vincent 也不再处于积极开发阶段,建议使用altair。
So if you want a pythonic d3, use altair.
所以如果你想要一个 pythonic d3,使用 altair。

