Consider a weighted graph 'net':

length = 500000;
vtx[] := Table[i <-> RandomInteger[{0, i - 1}], {i, 1, length}];
w = RandomInteger[{1, 100}, Length[vtx[]]]
net = Graph[vtx[], EdgeWeight -> w, GraphLayout -> {"SpringEmbedding", "EdgeWeighted" -> True}];
Export["net.png", net, "PNG"];

Unfortunately, Mathematica is unable to visualize such a network and save it to a file. Is there any way to do this?

  • 1
    $\begingroup$ Mathematica can generate such a graph just fine. What you seem to want is to visualize it. Look up the options of the graph layout method you are using and choose settings which result in the layout algorithms stopping sooner. $\endgroup$
    – Szabolcs
    May 19, 2019 at 8:26
  • $\begingroup$ You'll find tips here: mathematica.stackexchange.com/a/187205/12 $\endgroup$
    – Szabolcs
    May 19, 2019 at 8:27
  • $\begingroup$ Thanks to @Szabolcs. But I really want the graph to keep the edge length corresponding to the weights. If I use the "EdgeWeighted" -> True, Mathematica does not generate such a large network, unfortunately. It is doing well with smaller ones. And this is not a matter of RAM. $\endgroup$
    – ralph
    May 19, 2019 at 19:59
  • $\begingroup$ Thanks. But I still can not generate a graph such as this: drive.google.com/drive/folders/… $\endgroup$
    – ralph
    May 27, 2019 at 7:14
  • $\begingroup$ The first two columns are nodes and the third column is the edge weight (eg 898748 <-> 908885 weight is 28). To load data: w = Import["Weighted_graph.dat"]; w1 = w[[All, {1, 2}]]; w2 = Map[(#[[1]] <-> #[[2]]) &, w1]; weights= w[[All, 3]]; The idea is to generate a graph (to a file eg *.png), keeping the edge length equal to the weight values. $\endgroup$
    – ralph
    May 27, 2019 at 7:23


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.