# Editing DiGraph layout.

I have the following DiGraph, G, that I generated: C:\fakepath\z_tmp.png

This plot is generated by doing: G.plot()

I would like to be able to see the vertex labels more clearly on this plot.

In order to edit the DiGraph, I had tried to remove the nodes entirely and simply have the labels via the vertex_shape=None argument for graphplot(), however this seems to be unsupported for DiGraphs. I am open to other suggestions to alter this plot so that I may see labels clearly.

I am currently running Sage v8.9

edit retag close merge delete

maybe upgrade to 9.4 ? I do not see vertex label problem with 9.4

g = DiGraph( {-2: [0, -3],-3: [-4, -1],0: [-1, 2],2: [1],-4: [-2],-1: [1, -2] }  )
show(g)

( 2022-01-22 06:16:48 +0100 )edit

In the picture I have generated above, the issue is the labels are not simple integers but rather a tuple, for example something of the form: ((-2,2),5). These labels are covered by some arrows and also not entirely contained within the vertex nodes. I have tried to plot my DiGraph in the CoCalc lab which is version 9.4, but the result is the same as with version 8.9.

( 2022-01-23 03:08:12 +0100 )edit

Oops ! ok sorry @Bark.

( 2022-01-23 07:30:02 +0100 )edit

Sort by » oldest newest most voted

Let us first get a graph similar to your example

G = graphs.Grid2dGraph(5,5)
G.delete_vertices([(4, 0), (4, 1), (3, 0), (0, 3), (0, 4), (1, 4)])
D = DiGraph([(u, v) if u < v else (v, u) for u,v in G.edges(labels=False)])
g_pos = G.get_pos()
pos = {u: g_pos[u] for u in D}
D.set_pos(pos)
perm = {u: ((randint(-3, 3), randint(-3, 3)), randint(-3, 3)) for u in D}
H = D.relabel(perm=perm, inplace=False)


Then you can try

H.plot(vertex_size=4000, figsize=10)


Another method is to use d3.js (see the documentation for parameters)

I = DiGraph(H.edges())


and you get something like this

If you have dot2tex installed (see question 60815), you can also do:

I.set_latex_options(format='dot2tex')
view(I)


more