Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I want to add a new vertex to a graph, with fixed VertexCoordinates but when I use VertexAdd, the new graph does not have the VertexCoordinates of the previous one.

g = Graph[{1 -> 2}, VertexCoordinates -> {{0, 0.5}, {0.5, 0}}, 
  PlotRange -> 1]

This is the initial graph

g = VertexAdd[g, 3]

Adding a new vertex makes a new graph with automatic coordinates.

I tried to see if there is a way to define the coordinates when adding a new vertex but I could not find anything.

Also I was looking if there is something like:

SetProperty[g, VectorCoordinates -> {list of coordinates}]

To set coordinates for all vertices in a graph, but I could not find anything.

share|improve this question
2  
related questions: mathematica.stackexchange.com/questions/31014/… –  halmir Aug 27 '13 at 17:56

1 Answer 1

up vote 8 down vote accepted

Here is your Graph

g = Graph[{1 -> 2}, VertexCoordinates -> {{0, 0.5}, {0.5, 0}},PlotRange -> 1]

You can try this!

g = SetProperty[VertexAdd[g, {3, 4}],
VertexCoordinates-> PropertyValue[g, VertexCoordinates]~Join~{{.7, .6}, {-.2, -.3}}];

The graph will retain its VetexCoordinates

EdgeAdd[g, 1 -> 4]

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.