I am looking for other alternatives to render grpah and save as image from dot file. I can't use Graphviz tool in my work machine as I have restriction. In my search I found networkx python which has pydot/pygraphviz support through which
i) I can import dot files and convert to networkx graph
ii) I can create pydot/grphviz graph using those packages API and convert to networkx graph.
I have bleow dot code which I want to convert to networkx graph using python and later plot using matplotlib for rendering and saving graph as image.
digraph aud {
graph [fontname=sans fontsize=10 label="Graph" labelloc=t nodesep=.1 rankdir=LR ranksep=.2]
node [fontname=sans fontsize=9 margin="0.0,0.0" shape=box style="filled,rounded"]
edge [fontname=monospace fontsize=9 labelfontsize=6]
subgraph cluster_0_filesrc {
graph [color=black fillcolor="#ffaaaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label="filesrc
location=song.ogg"
subgraph cluster_0_filesrc_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_0_filesrc_src0 [label=src]
}
}
subgraph cluster_1_decodebin {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=decodebin
subgraph cluster_1_decodebin_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_1_decodebin_sink0 [label=sink]
}
subgraph cluster_1_decodebin_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_1_decodebin_src0 [label=src]
}
}
subgraph cluster_2_tee {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label="tee
t"
subgraph cluster_2_tee_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_2_tee_sink0 [label=sink]
}
subgraph cluster_2_tee_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_2_tee_src0 [label=src_0]
cluster_2_tee_src1 [label=src_1]
}
}
subgraph cluster_3_queue {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=queue
subgraph cluster_3_queue_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_3_queue_sink0 [label=sink]
}
subgraph cluster_3_queue_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_3_queue_src0 [label=src]
}
}
subgraph cluster_4_audioconvert {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=audioconvert
subgraph cluster_4_audioconvert_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_4_audioconvert_sink0 [label=sink]
}
subgraph cluster_4_audioconvert_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_4_audioconvert_src0 [label=src]
}
}
subgraph cluster_5_audioresample {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=audioresample
subgraph cluster_5_audioresample_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_5_audioresample_sink0 [label=sink]
}
subgraph cluster_5_audioresample_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_5_audioresample_src0 [label=src]
}
}
subgraph cluster_6_autoaudiosink {
graph [color=black fillcolor="#aaaaff" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=autoaudiosink
subgraph cluster_6_autoaudiosink_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_6_autoaudiosink_sink0 [label=sink]
}
}
subgraph cluster_7_queue {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=queue
subgraph cluster_7_queue_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_7_queue_sink0 [label=sink]
}
subgraph cluster_7_queue_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_7_queue_src0 [label=src]
}
}
subgraph cluster_8_audioconvert {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=audioconvert
subgraph cluster_8_audioconvert_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_8_audioconvert_sink0 [label=sink]
}
subgraph cluster_8_audioconvert_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_8_audioconvert_src0 [label=src]
}
}
subgraph cluster_9_goom {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=goom
subgraph cluster_9_goom_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_9_goom_sink0 [label=sink]
}
subgraph cluster_9_goom_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_9_goom_src0 [label=src]
}
}
subgraph cluster_10_videoconvert {
graph [color=black fillcolor="#aaffaa" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=videoconvert
subgraph cluster_10_videoconvert_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_10_videoconvert_sink0 [label=sink]
}
subgraph cluster_10_videoconvert_src {
graph [label="" style=invis]
node [color=black fillcolor="#ffaaaa" height=0.2 style="filled,solid"]
cluster_10_videoconvert_src0 [label=src]
}
}
subgraph cluster_11_autovideosink {
graph [color=black fillcolor="#aaaaff" fontname="Bitstream Vera Sans" fontsize=8 style="filled,rounded"]
label=autovideosink
subgraph cluster_11_autovideosink_sink {
graph [label="" style=invis]
node [color=black fillcolor="#aaaaff" height=0.2 style="filled,solid"]
cluster_11_autovideosink_sink0 [label=sink]
}
}
cluster_1_decodebin_sink0 -> cluster_1_decodebin_src0 [style=invis]
cluster_2_tee_sink0 -> cluster_2_tee_src0 [style=invis]
cluster_3_queue_sink0 -> cluster_3_queue_src0 [style=invis]
cluster_4_audioconvert_sink0 -> cluster_4_audioconvert_src0 [style=invis]
cluster_5_audioresample_sink0 -> cluster_5_audioresample_src0 [style=invis]
cluster_7_queue_sink0 -> cluster_7_queue_src0 [style=invis]
cluster_8_audioconvert_sink0 -> cluster_8_audioconvert_src0 [style=invis]
cluster_9_goom_sink0 -> cluster_9_goom_src0 [style=invis]
cluster_10_videoconvert_sink0 -> cluster_10_videoconvert_src0 [style=invis]
cluster_0_filesrc_src0 -> cluster_1_decodebin_sink0
cluster_1_decodebin_src0 -> cluster_2_tee_sink0
cluster_2_tee_src0 -> cluster_3_queue_sink0
cluster_3_queue_src0 -> cluster_4_audioconvert_sink0
cluster_4_audioconvert_src0 -> cluster_5_audioresample_sink0
cluster_5_audioresample_src0 -> cluster_6_autoaudiosink_sink0
cluster_2_tee_src1 -> cluster_7_queue_sink0
cluster_7_queue_src0 -> cluster_8_audioconvert_sink0
cluster_8_audioconvert_src0 -> cluster_9_goom_sink0
cluster_9_goom_src0 -> cluster_10_videoconvert_sink0
cluster_10_videoconvert_src0 -> cluster_11_autovideosink_sink0
}
For creating graph using graphviz tool I am using below command: dot -Tpng Graph.dot -o Graph_dot.png graph rendered using Graphviz tool
I am using below python code,
import pydot
import networkx as nx
import matplotlib.pyplot as plt
graphs = pydot.graph_from_dot_file('Gstreamer_Pipeline.gv')
graph = graphs[0]
gst_nx = nx.drawing.nx_pydot.from_pydot(graph)
position = nx.nx_pydot.pydot_layout(gst_nx)
plt.figure()
nx.draw_networkx(gst_nx, position)
plt.axis('on')
plt.show()
I am not getting same graph as like grpahviz tool output. attached the graphviz tool output graph file. could someone help how to plot the networkx graph with same node/edge attributes like graphviz tool output