# Setting vertex coordinates on a graph

**URL:** <https://community.wolfram.com/t/setting-vertex-coordinates-on-a-graph/10415>\
**Category:** Ideas\
**Tags:** graphs-and-networks\
**Created:** [April 27, 2017, 8:25am UTC](https://community.wolfram.com/t/setting-vertex-coordinates-on-a-graph/10415 "2017-04-27T08:25:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![szhorvat](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/szhorvat/32/3531_2.png) [@szhorvat](https://community.wolfram.com/u/szhorvat)\
**Post date:** [April 27, 2017, 8:25am UTC](https://community.wolfram.com/t/setting-vertex-coordinates-on-a-graph/10415/1 "2017-04-27T08:25:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zyd199012](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/zyd199012/32/7092_2.png) [@zyd199012](https://community.wolfram.com/u/zyd199012)\
**Post date:** [April 27, 2017, 9:29am UTC](https://community.wolfram.com/t/setting-vertex-coordinates-on-a-graph/10415/2 "2017-04-27T09:29:59Z")

</div>

As the documentation of `VertexCoordinates`,it is a bug indeed presisting many version.

![Mathematica graphics](http://i.stack.imgur.com/L3f4b.png)

The method based on `Thread` always is my choice currently.

```
Graph[g, VertexCoordinates -> Thread[VertexList[g] -> RandomReal[1

```
