在networkx中绘制完整neo4j图的最简单方法

时间:2022-02-18 23:59:16

I have a neo4j graph and I want to draw the entire graph in an ipython notebook with network x. How do I go about doing that?

我有一个neo4j图,我想在一个带有网络x的ipython笔记本中绘制整个图形。我该怎么做呢?

Something like this?

像这样的东西?

g1 = nx.neo4j_graph
nx.draw(g1)
plt.show()

1 个解决方案

#1


7  

Use ipython-cypher to write a Cypher query and then convert the results to a NetworkX graph. Install it with pip install ipython-cypher.

使用ipython-cypher编写Cypher查询,然后将结果转换为NetworkX图。使用pip install ipython-cypher安装它。

import networkx as nx
%load_ext cypher
%matplotlib inline

results = %cypher MATCH p = ()-[]-() RETURN p

g = results.get_graph()

nx.draw(g)

Drawing your entire graph is expensive if it is large. Consider only drawing the subgraphs you're interested in. You'll also have to tweak the query slightly if you want nodes with degree 0.

如果图表很大,绘制整个图表会很昂贵。考虑只绘制你感兴趣的子图。如果你想要0度的节点,你还需要稍微调整一下查询。

#1


7  

Use ipython-cypher to write a Cypher query and then convert the results to a NetworkX graph. Install it with pip install ipython-cypher.

使用ipython-cypher编写Cypher查询,然后将结果转换为NetworkX图。使用pip install ipython-cypher安装它。

import networkx as nx
%load_ext cypher
%matplotlib inline

results = %cypher MATCH p = ()-[]-() RETURN p

g = results.get_graph()

nx.draw(g)

Drawing your entire graph is expensive if it is large. Consider only drawing the subgraphs you're interested in. You'll also have to tweak the query slightly if you want nodes with degree 0.

如果图表很大,绘制整个图表会很昂贵。考虑只绘制你感兴趣的子图。如果你想要0度的节点,你还需要稍微调整一下查询。