from igraph import Graph, Plot
from cairo import Context
# Create two graphs
g = Graph.Ring(5)
g2 = Graph.Full(5)
# Create a figure containing the two graphs
fig = Plot("test.pdf", bbox=(800, 360), background="white")
fig.add(g, bbox=(20,20,340,340))
fig.add(g2, bbox=(460,20,780,340))
# Force the figure to be drawn
fig.redraw()
# Create a Cairo drawing context
ctx = Context(fig.surface)
# Draw an arrow
ctx.set_source_rgb(0,0,0)
ctx.move_to(360,180)
ctx.line_to(430,180)
ctx.stroke()
ctx.move_to(440,180)
ctx.line_to(430,170)
ctx.line_to(430,190)
ctx.line_to(440,180)
ctx.fill()
# Save the figure
fig.save()
ArrowEdgeDrawer
不是用来在绘图上绘制任意箭头的;顾名思义,它是一个edge抽屉。Graph drawer类默认使用ArrowEdgeDrawer
将无向边绘制为直线,将有向边绘制为带箭头的直线,因此ArrowEdgeDrawer
的公共方法将两个图顶点作为参数,而不是在绘图上任意点。以一种非常复杂的方式,你可以创建一个包含两个不可见顶点(顶点形状为"none"
)和两个顶点之间有向边的“假”图,然后将这个图覆盖在实际的图形之上,但我认为直接在绘图画布上绘制要容易得多。igraph使用Cairo作为绘图后端,您可以使用适当构造的Plot
对象的surface
属性访问igraph绘图的Cairo表面。然后可以为曲面创建Cairo绘图上下文并直接在其上绘制。例如:相关问题 更多 >
编程相关推荐