我目前正在尝试使用图形工具在同一图形上绘制多个图形,但是我遇到了一个奇怪的错误。
我正在使用以下事实:graph_draw()函数允许指定应在其中绘制图形的容器。但是,该图绘制在图的另一侧,垂直(而不是水平)在轴的外部(请参见图1)。代码很简单:
#thG is a list of networkx Graph() objects
nG = len(thG)
nrow = int(nG/ncol)+1
a = 2 #size of a single graph
fig = plt.figure(figsize=(ncol*a,nrow*a))
w = 1./ncol
h = 1./nrow
for z,G in enumerate(thG):
#position of the graph
x = (z%ncol)*w
y = 1.-h*(1+z/ncol)
ax = fig.add_axes([x,y,w,h])
#plot preparation
nodes = G.nodes()
nN = len(nodes)
index = {nodes[i]:i for i in range(nN)}
#graph for plotting
G0 = gt.Graph(directed=False)
v_id = G0.new_vertex_property("int") #node ID
vlist = []
for n in nodes:
v = G0.add_vertex()
v_id[v] = n
vlist.append(v)
for n,p in G.edges():
i,j = index[n],index[p]
e = G0.add_edge(vlist[i],vlist[j])
#plot graph
pos = sfdp_layout(G0,eweight=e_w)
graph_draw(G0,pos,
vertex_size=5,
mplfig=ax
)
plt.savefig("graph_steps_"+str(z)+".png")
任何人都知道发生了什么事以及如何解决这个问题?