Hi,
I'm using the code below to fix the position of a root vertex. I'm developing an application and I wanna make sure that the root vertex is always located in the same place.
g = Graph() v_pin = g.new_vertex_property("bool") v = g.add_vertex() v_pin[v] = True #root vertex ... pos = sfdp_layout(g, pin=v_pin) graph_draw(g, ...)
I suppose it's working, but how I can confirm which one is the root vertex in my result?
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4025773/mxt.png
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 05.10.2014 06:42, luistavares wrote:
Hi,
I'm using the code below to fix the position of a root vertex. I'm developing an application and I wanna make sure that the root vertex is always located in the same place.
g = Graph() v_pin = g.new_vertex_property("bool") v = g.add_vertex() v_pin[v] = True #root vertex ... pos = sfdp_layout(g, pin=v_pin) graph_draw(g, ...)
I suppose it's working, but how I can confirm which one is the root vertex in my result?
There are many ways: You can change the shape, size, and color of the vertices to your liking. It is all described in the documentation.
For instance, to change the color of the root you would do:
c = g.new_vertex_property("int") c[root] = 1 graph_draw(g, vertex_fill_color=c)
Best, Tiago
Thanks Tiago. Just one more question. Is there a way to fix the position of the root node?The pin parameter is not working like I expect. Date: Mon, 6 Oct 2014 00:38:29 +0200 From: tiago@skewed.de To: graph-tool@skewed.de Subject: Re: [graph-tool] Fixing position of root vertex
On 05.10.2014 06:42, luistavares wrote:
Hi,
I'm using the code below to fix the position of a root vertex. I'm developing an application and I wanna make sure that the root vertex is always located in the same place.
g = Graph() v_pin = g.new_vertex_property("bool") v = g.add_vertex() v_pin[v] = True #root vertex ... pos = sfdp_layout(g, pin=v_pin) graph_draw(g, ...)
I suppose it's working, but how I can confirm which one is the root vertex in my result?
There are many ways: You can change the shape, size, and color of the vertices to your liking. It is all described in the documentation.
For instance, to change the color of the root you would do:
c = g.new_vertex_property("int") c[root] = 1 graph_draw(g, vertex_fill_color=c)
Best, Tiago
On 06.10.2014 03:37, Luis Antonio Tavares wrote:
Thanks Tiago.
Just one more question. Is there a way to fix the position of the root node? The pin parameter is not working like I expect.
Please provide a short self-contained example which shows the problem you are experiencing.
Best, Tiago
Ok Tiago,
Here is the problem, the root node is located in a different place each time I run the code. See the image (root node is in red).
I wanna fix the place for the root node. For example, it should always be located at the bottom of the result.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 06.10.2014 17:02, luistavares wrote:
Ok Tiago,
Here is the problem, the root node is located in a different place each time I run the code. See the image (root node is in red).
I wanna fix the place for the root node. For example, it should always be located at the bottom of the result.
The "pin" parameter does exactly that, it allows you to fix the absolute position of selected nodes. What it does not do is fix the relative position to other nodes, which seems to be what you want. Unfortunately there is no easy way to do that, since the nodes which are unpinned are allowed to be placed in any way.
Perhaps what you should do is to do an interactive layout with graph_draw(), and position/rotate the layout by hand.
Best, Tiago
Hi Tiago,
Let me get this straight, when I use the "pin" parameter I fix the position of the root node, but when I use the layout algorithm the position of other nodes end up interfering with the position of the root node at the end. Is that what is happening? I just need to fix the position of the root node and it needs to be done im an automatic way.
Thanks for your help. I really appreciate it.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 06.10.2014 23:18, luistavares wrote:
Let me get this straight, when I use the "pin" parameter I fix the position of the root node, but when I use the layout algorithm the position of other nodes end up interfering with the position of the root node at the end. Is that what is happening?
No. The actual (absolute) position of the root node remains fixed (you can check it by inspecting the position value before and after the layout). But since the other nodes can be placed in any way, their relative position to the root node (above it, below it, etc) is arbitrary.
I wanna fix the place for the root node. For example, it should always be located at the bottom of the result.
Again, your are thinking on their relative positions. The layout algorithm has no idea which side is up, down, etc. The graph_draw() function just frames and re-scales the nodes using their positions, but the layout algorithm itself is fully rotational and translational invariant.
If you want to have some control over their relative positions, you can pin the root node, and place the other ones initially more or less in the region you would like them to stay at the end, relative to the root node. There is no guarantee that they will not move during the layout, but the probability is higher.
Best, Tiago
Thanks Tiago.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
Hi,
I'm using this post as a doubt arose related to this problem. I generated positions for the main paths of my graph and let them fixed by pin property. But after using the function sfdp_layout all the positions have changed. Please, let me know if this is actually the expected behavior. Following image showing the generated positions and the positions after using sfdp_layout.
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4025880/graph.png
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
Please,
Could anyone help me with this question?
Thanks.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
Please can you post the relevant sample of code?
Cheers
Charlie
On 23 Nov 2014, at 01:35, luistavares luis.tavares@msn.com wrote:
Please,
Could anyone help me with this question?
Thanks.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com. _______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
Ok.
After generating a long graph, I use linspace function to generate positions for the main paths of the graph. So I fixed these positions using the pin property. But after calling the function sfdp_layout all positions are changed. Is this the expected behavior? I presented the results in the previous post. Here is my relevant code:
pin = g.new_vertex_property("bool") pos = g.new_vertex_property("vector<double>") v_c = g.new_vertex_property("double") v_s = g.new_vertex_property("int")
# I created a graph with 11000 nodes.
# setting positions for the main path position = np.linspace(0.0, 12.0, main_path_size) for i,idx in enumerate(main_path_i): pin[g.vertex(idx)] = True pos[g.vertex(idx)] = (0, position[i]) v_c[g.vertex(idx)] = 50 # color v_s[g.vertex(idx)] = 10 # size
# setting positions for the second main path position = np.linspace(0.0, 12.0, sec_path_size) for i,idx in enumerate(sec_path_i): pin[g.vertex(idx)] = True pos[g.vertex(idx)] = (position[i], 12.0) v_c[g.vertex(idx)] = 250 # color v_s[g.vertex(idx)] = 10 # size
# setting positions for the thirmain path position = np.linspace(0.0, 12.0, thi_path_size) for i,idx in enumerate(thi_path_i): pin[g.vertex(idx)] = True pos[g.vertex(idx)] = (-position[i], 12.0) v_c[g.vertex(idx)] = 350 # color v_s[g.vertex(idx)] = 10 # size
# calling the layout function pos = gt.sfdp_layout(g, pin=pin, pos=pos)
gt.graph_draw(g, pos, output_size=(1000, 1000), vertex_fill_color=v_c, vertex_size=v_s, vcmap=mat.cm.jet, output='mxt.png', fmt='png')
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
Try setting the pin properties of the vertices you want moved to False in your pin map.
Cheers,
Charlie
On 23 Nov 2014, at 19:47, luistavares luis.tavares@msn.com wrote:
Ok.
After generating a long graph, I use linspace function to generate positions for the main paths of the graph. So I fixed these positions using the pin property. But after calling the function sfdp_layout all positions are changed. Is this the expected behavior? I presented the results in the previous post. Here is my relevant code:
pin = g.new_vertex_property("bool") pos = g.new_vertex_property("vector<double>") v_c = g.new_vertex_property("double") v_s = g.new_vertex_property("int")
# I created a graph with 11000 nodes.
# setting positions for the main path position = np.linspace(0.0, 12.0, main_path_size) for i,idx in enumerate(main_path_i): pin[g.vertex(idx)] = True pos[g.vertex(idx)] = (0, position[i]) v_c[g.vertex(idx)] = 50 # color v_s[g.vertex(idx)] = 10 # size
# setting positions for the second main path position = np.linspace(0.0, 12.0, sec_path_size) for i,idx in enumerate(sec_path_i): pin[g.vertex(idx)] = True pos[g.vertex(idx)] = (position[i], 12.0) v_c[g.vertex(idx)] = 250 # color v_s[g.vertex(idx)] = 10 # size
# setting positions for the thirmain path position = np.linspace(0.0, 12.0, thi_path_size) for i,idx in enumerate(thi_path_i): pin[g.vertex(idx)] = True pos[g.vertex(idx)] = (-position[i], 12.0) v_c[g.vertex(idx)] = 350 # color v_s[g.vertex(idx)] = 10 # size
# calling the layout function pos = gt.sfdp_layout(g, pin=pin, pos=pos)
gt.graph_draw(g, pos, output_size=(1000, 1000), vertex_fill_color=v_c, vertex_size=v_s, vcmap=mat.cm.jet, output='mxt.png', fmt='png')
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com. _______________________________________________ graph-tool mailing list graph-tool@skewed.de http://lists.skewed.de/mailman/listinfo/graph-tool
Hi Charlie,
I did what you suggested, I set to False the pin properties of the vertices I want to move. But after calling the layout function the positions of all vertices are still changing.
Anyway, thanks for your help.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 24.11.2014 00:22, luistavares wrote:
Hi Charlie,
I did what you suggested, I set to False the pin properties of the vertices I want to move. But after calling the layout function the positions of all vertices are still changing.
The pin values of the vertices for which you want the positions to stay the same must be set to True, and the others to False. After you create a new property map, all its values are per default False (zero). If you just set the ones you want to move to 'False' you haven't accomplished anything. You must also set the ones you want fixed to 'True'.
When you have problems like this it is very difficult to help if you don't post a small self-contained example which shows the problem. I don't mean a fragment of code, I mean something I can run myself, together with the graph, etc.
Best, Tiago
Hi Tiago,
Thanks for your attention. When I use a small example it works fine. But the problem occurs when I use a big graph with 11000 vertices as I showed in the image in the previous post. Could I send a link containing all my edges and a the code here?
I based on this small example that is working fine:
import graph_tool.all as gt import matplotlib as mat
g = gt.Graph() g.add_vertex(7) g.add_edge(0,1) g.add_edge(1,2) g.add_edge(2,3) g.add_edge(2,4) g.add_edge(3,5) g.add_edge(2,6)
pos = g.new_vertex_property("vector<double>") pin = g.new_vertex_property("bool")
pos[g.vertex(0)] = (0, 0) pos[g.vertex(1)] = (2, 2) pos[g.vertex(2)] = (4, 2) pos[g.vertex(3)] = (6,6) pos[g.vertex(4)] = (0,4) pos[g.vertex(5)] = (9,8) pos[g.vertex(6)] = (0,8)
pin[g.vertex(0)] = True pin[g.vertex(1)] = True pin[g.vertex(2)] = True pin[g.vertex(3)] = True pin[g.vertex(4)] = False pin[g.vertex(5)] = False pin[g.vertex(6)] = False
gt.graph_draw(g, pos, output_size=(1000, 1000), edge_pen_width=1.3, vertex_size=10, vcmap=mat.cm.jet, output='fixed_positions.png', fmt='png')
pos = gt.sfdp_layout(g, pin=pin, pos=pos)
gt.graph_draw(g, pos, output_size=(1000, 1000), edge_pen_width=1.3, vertex_size=10, vcmap=mat.cm.jet, output='final_positions.png', fmt='png')
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 24.11.2014 14:26, luistavares wrote:
Hi Tiago,
Thanks for your attention. When I use a small example it works fine. But the problem occurs when I use a big graph with 11000 vertices as I showed in the image in the previous post.
Try using the option "multilevel=False" in sfdp_layout(). Does that solve the problem?
Best, Tiago
Hi Thiago,
Using this parameter actually positions are fixed, but my layout is messy.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 25.11.2014 02:45, luistavares wrote:
Hi Thiago,
Using this parameter actually positions are fixed, but my layout is messy.
I'm not sure what you expected.
Best, Tiago
I was expecting that I could fix the positions of the main paths of the graph without interfering so much in the final layout. I thought I could at least define my main path as a straight line (the blue path in the image).
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4025894/graph.png
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
Thanks Tiago.
Just one more question. Is there a way to fix the position of the root node? The pin parameter is not working like I expect.
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.