Reputation: 941
I'm trying to plot a graph with igraph on Python, according to the following code:
import numpy as np
import igraph as ig
def make_blue(brightness):
brightness = round(255 * brightness)
return [255 - brightness, 255 - brightness, 255]
N = 6
adj_matr = np.random.random((N, N))
weights = sum(adj_matr.tolist(), [])
g = ig.Graph.Weighted_Adjacency(adj_matr.tolist(), mode=ig.ADJ_DIRECTED, attr="weight", loops=True)
g.vs["color"] = "rgb(224,224,224)"
g.es["arrow_size"] = 0.7
for i in range(0, pow(N, 2)):
rgb_color = make_blue(weights[i])
color_string = "rgb(" + str(rgb_color[0]) + "," + str(rgb_color[1]) + "," + str(rgb_color[2]) + ")"
g.es[i]["color"] = color_string
g.es[1]["color"] = "red"
ig.plot(g, "My_Graph.svg", bbox=(700, 700), margin = 100, vertex_label=map(str, np.arange(N)))
The result is shown below:
I would like to plot the red arrow on the blue ones, since it is partially hidden.
I have tried with something like fig = Plot(); fig.add(g)
to superimpose the red arrow on the others, but then I don't know how to save the whole plot to a svg file (the function fig.save()
seems to save only to a png format).
Do you know how to fix this problem? Thanks in advance for your help!
Upvotes: 1
Views: 624
Reputation: 48051
Custom edge ordering is not possible yet with the latest stable version of igraph at the time of writing. The edge_order
keyword argument has recently been added to the development version and you can inspect the changes required to make this work in the GitHub repo of igraph.
If you do not feel like patching your copy of igraph, you can try drawing the graph first, followed by drawing the graph on top of it again, but this time make all but the red edge transparent (set their color to rgba(0,0,0,0)
). This can be done with something like:
fig = Plot(target="test.svg")
fig.add(g, ...add every usual plot parameter here...)
g.es["color"] = "rgba(0,0,0,0)"
g.es[your_red_edge]["color"] = "red"
fig.add(g, ...add plot parameters here again...)
fig.save()
Upvotes: 2