The following bug caused me some headache, so I thought I would share the workaround.
Sometimes trying to set VertexCoordinates
on a graph failed mysteriously, at other times it worked fine. I could not figure out why. It turns out that it does not like packed arrays.
This fails:
g = GraphData[{"BananaTree", {4, 5}}];
SetProperty[g, VertexCoordinates -> RandomReal[1, {21, 2}]]
This works:
SetProperty[g,
VertexCoordinates ->
Developer`FromPackedArray@RandomReal[1, {21, 2}]]
Update: This does not work either. I did not pay attention. The command does not "fail", but the coordinates are not set.
The following really does work:
SetProperty[g, VertexCoordinates -> Thread[VertexList[g] -> RandomReal[1, {21, 2}]]]
I am not sure why this is necessary as even the first command works just fine on RandomGraph[{21,50}]
. Now you can see how frustrating it is to try to write robust packages that use graphs. You never know when you'll bump into yet another weird failure.