非常方便,graph-tool.draw.graph_draw
可以让您指定一个 matplotlib Axes 对象作为绘图的画布。不太方便,坐标系不对齐。以下脚本演示了该问题。有没有比手动反转给一个或另一个坐标更简单的解决方法?
import matplotlib
matplotlib.use('cairo')
from matplotlib import pyplot
import graph_tool.all
x = [0, 1]
y = [0, 1]
g = graph_tool.Graph()
pos = g.new_vertex_property('vector<float>')
v_0 = g.add_vertex()
v_1 = g.add_vertex()
g.add_edge(u, v)
pos[v_0] = [0,0]
pos[v_1] = [1,1]
pyplot.plot(x, y)
ax = pyplot.gca()
graph_tool.draw.graph_draw(g, pos=pos, mplfig=ax)
pyplot.savefig('flip.png')