我在哪里告诉Pyplot,我想绘制Graph G? 我猜nx。绘制使用matplotlib.pyplot。{plot等...} 因此,如果我想绘制2个图:
import matplotlib.pyplot
import networkx as nx
G=nx.path_graph(8)
E=nx.path_graph(30)
nx.draw(G)
matplotlib.pyplot.figure()
nx.draw(E)
matplotlib.pyplot.show()
然后...很少的实验
import networkx as nx
G=nx.path_graph(8)
E=nx.path_graph(30)
nx.draw(G)
import matplotlib.pyplot
matplotlib.pyplot.figure()
nx.draw(E)
import matplotlib.pyplot as plt
plt.show()
请不要对这个愚蠢的代码杀死我,我只是想理解 - networkx如何绘制一些matplotlib,虽然它甚至还没有导入!
P.S:对不起我的英语。如果要分别绘制图形或创建单个
Axes
对象,则创建两个不同的轴。例如:
要:
如果您想要两个不同的图形对象,然后像这样分别创建它们:
G = nx.path_graph(8)
E = nx.path_graph(30)
# one plot, both graphs
fig, ax = subplots()
nx.draw(G, ax=ax)
nx.draw(E, ax=ax)
youlding:
最终,您可以根据需要创建一个子图,例如:
G = nx.path_graph(8)
E = nx.path_graph(30)
# two separate graphs
fig1 = figure()
ax1 = fig1.add_subplot(111)
nx.draw(G, ax=ax1)
fig2 = figure()
ax2 = fig2.add_subplot(111)
nx.draw(G, ax=ax2)
在:
对于任何值得的看来,对于
G = nx.path_graph(8)
E = nx.path_graph(30)
pos=nx.spring_layout(E,iterations=100)
subplot(121)
nx.draw(E, pos)
subplot(122)
nx.draw(G, pos)
的api来说,to to and to to and api是没有用的。并没有真正挖掘为什么这样做,只是以为我会指出的。
源代码非常简单:ax
使用nx.draw
如果不存在,则将一个
matplotlib
对象添加到图中,否则使用pylab
.从环境中获取它。制作情节面颜色白
turn
nx.draw
gca
用内部功能绘制它从轴上伸出
如果我们处于互动模式,请绘制并列出任何被抓住的例外
pylab