How to properly plot a tree (27k nodes) using a circular tree / leave layout
I have this (unbalanced) tree with 27k+ nodes. It is an hierachy. Now I would to plot it as such to obtain a plot something like this (no idea how you would describe it, but I would call it a circular leave tree...?
However, I am unable to achieve such a result unfortunately. I have already tried igraph
, Networkx
, Maltego
, Graphviz
, Gephi
. Hopefully someone can help me / give me tips & tricks or hints.
Maltego
Gives me quiet easily the following. However I cannot export it to pdf. Furthermore it has this wierd expansion on the top going to the left. I would be able to 'manually' (minimize) move it. However that is not what I would like.
This is btw in my view (with the manual fix) the best result. But I cannot export it to vector or high-res image.
igraph
import igraph as ig
bigGraphAsTupleList = (('a','b'),('b','c'),('b','d'), ..., ('c','e'))
g = ig.Graph.TupleList(bigGraphAsTupleList)
layout = g.layout("rt_circular") #fr (fruchterman reingold), tree, circle, rt_circular (reingold_tilford_circular)
# bbox = size of picture
ig.plot(g,layout=layout,bbox=(10000,10000),target='mygraph.png')
This gives me something like below.
fruchterman reingold (so much overlap of nodes and connections)
Networkx
import networkx as nx
import matplotlib.pyplot as plt
G = nx.Graph()
G.add_edge(...) #build graph
nx.draw_circular(G) #nx.draw_spring(G) #nx.draw_spectral
plt.draw()
plt.show()
Graphviz (via Networkx)
Also a wierd result a bit similar as the next one Maltego. However
import networkx as nx
import matplotlib.pyplot as plt
import pydot
from networkx.drawing.nx_pydot import graphviz_layout
G = nx.Graph()
G.add_edge(...) #build graph
pos = graphviz_layout(G, prog="circo")
plt.figure(1,figsize=(60,60))
nx.draw(G, pos,node_size=10)
plt.show(block=False)
plt.savefig("Graph.png", format="PNG")
do you know?
how many words do you know
See also questions close to this topic
-
How can I speed up the routing process in OSMNX?
Say I have two taxi orders with Origin1、Destination1 and Origin2、Destination2(O1,O2,D1,D2). I want to calculate the possibility of ridesharing, so I need the path between two different points. And, here's my code:
def path_time(point1, point2): path = ox.distance.shortest_path(road, point1, point2, weight='travel_time') if path is None: #If there isn't a path, a big weight will be set, and it won't be selected during the matching process. route_time = 9999 else: route_time = int(sum(ox.utils_graph.get_route_edge_attributes(road, path, "travel_time"))) return route_time,path
Since there is four points, I need to do this six times, where tp means travel path :
tpO1O2 = path_time(O1,O2) tpO1D1 = path_time(O1,D1) tpO1D2 = path_time(O1,D2) tpO2D1 = path_time(O2,D1) tpO2D2 = path_time(O2,D2) tpD1D2 = path_time(D1,D2)
It's okay if I only have two points, but I got a 2 million order set, and each order has hundreds of potential matched orders. So this will take me a lot of time.
Does anyone knows how can I speed up this process? Thank you!
-
Object and Pointers Graph Representation in Ruby
I am studying how to represent a graph in memory with Objects and Pointers in ruby and cannot find a representation of this anywhere. Can anyone point me in the right direction of how to build this ds?
-
there are some issues in this family tree I made
I have this good family tree but the problem is that the page is funcy like everything is on top of each other how can I fix it (it's better to try it in a coding app because CSS doesn't work here (if it does I don't know))
<meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>family tree</title> <link rel="stylesheet" href="style.css"> <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css"
rel="stylesheet" id="bootstrap-css">
-
great great great grand father
-
great great grand father
-
great grand father
-
grand mother
- grand father
- mother
-
father
- child
- child
- child
- child
- child
- child
-
father
- mother
-
grand mother
- child
- child
- child
- child
- child
-
great grand father
- father
-
mother
- child
- child
-
great great grand father
- grand father
</li> </ul> </li> </ul> </li> </ul> </li> <li> <a href="#">father</a> <ul> <li><a href="#">Grand Child</a></li> <li> <a href="#">Grand Child</a> <ul> <li> <a href="#">Great Grand Child</a> </li> <li> <a href="#">Great Grand Child</a> </li> <li> <a href="#">Great Grand Child</a> </li> </ul> </li> <li><a href="#">Grand Child</a></li> </ul> </li> </ul> </li> </ul> </div> </div> </div> </body> </html>
* { margin: 0; padding: 0; } .tree ul { padding-top: 20px; position: relative; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .tree li { float: left; text-align: center; list-style-type: none; position: relative; padding: 20px 5px 0 5px; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .tree li::before, .tree li::after { content: ''; position: absolute; top: 0; right: 50%; border-top: 1px solid #ccc; width: 50%; height: 20px; } .tree li::after { right: auto; left: 50%; border-left: 1px solid #ccc; } .tree li:only-child::after, .tree li:only-child::before { display: none; } .tree li:only-child { padding-top: 0; } .tree li:first-child::before, .tree li:last-child::after { border: 0 none; } .tree li:last-child::before { border-right: 1px solid #ccc; border-radius: 0 5px 0 0; -webkit-border-radius: 0 5px 0 0; -moz-border-radius: 0 5px 0 0; } .tree li:first-child::after { border-radius: 5px 0 0 0; -webkit-border-radius: 5px 0 0 0; -moz-border-radius: 5px 0 0 0; } .tree ul ul::before { content: ''; position: absolute; top: 0; left: 50%; border-left: 1px solid #ccc; width: 0; height: 20px; } .tree li a { border: 1px solid #ccc; padding: 5px 10px; text-decoration: none; color: #666; font-family: arial, verdana, tahoma; font-size: 11px; display: inline-block; border-radius: 5px; -webkit-border-radius: 5px; -moz-border-radius: 5px; transition: all 0.5s; -webkit-transition: all 0.5s; -moz-transition: all 0.5s; } .tree li a:hover, .tree li a:hover+ul li a { background: #c8e4f8; color: #000; border: 1px solid #94a0b4; } .tree li a:hover+ul li::after, .tree li a:hover+ul li::before, .tree li a:hover+ul::before, .tree li a:hover+ul ul::before { border-color: #94a0b4; }
-
great great great grand father
-
Binary tree not clearing with each loop iteration
I am using a binary tree to convert prefix expression into infix, and then solving them. That part works fully.
My issue is the input loop I set up is adding on the new expression to the old tree, resulting in an error. I have tried clearing the linked list, and manually created a method to empty out the tree. But every time, the output I have is showing the new expression appended to the previous one, rather than creating a whole new tree.
public static void main(final String[] args) { Scanner listener = new Scanner(System.in); System.out.println(); System.out.println("Enter a prefix expression Separated by space!! (Enter 'done' to end): "); String line = listener.nextLine(); while(!line.equalsIgnoreCase("done")){ System.out.println(line); if(line.length()<=1){ System.out.println("Invalid expression"); listener.close(); return;} instances(line); line = new String(); line = listener.nextLine(); } listener.close(); } public static void instances(String input){ System.out.println("The input expression was \n\t"+ input +"\n"); String[] in = input.split(" "); LinkedList<String> queue = new LinkedList<>(Arrays.asList(in)); TreeNode root = new TreeNode(queue, null); System.out.println("Expression as infix: "); inOrder(root); System.out.println(infix_string); String[] infix = infix_string.split(" "); Stack infix_stack = new Stack(infix); System.out.print("\t" + infix_stack + " = "); infix_stack.answer(); System.out.println(); System.out.println("Enter a prefix expression Separated by space!! (Enter 'done' to end): "); queue.clear(); clearTree(root); } public static void clearTree(TreeNode root){ if(root != null){ clearTree(root.left); clearTree(root.right); root=null; } } }
-
How to apply Word2vec for the Pandas series
I am having data with skill columns and the total length of the file is around 500thousand. I wanted to apply word2vec to the data. Can anyone give me insights on how to apply word2vec to my data.
skill Product Management,RPM,Progress 4GL,IP,CAMEL,Prince2 Foundation,Continuous Integration,GSM(HLR,MSC),Programming,SS7,INAP,ClearCase,SS7 protocol,Software Development,Shell Scripting,GPRS(SGSN,GGSN),MySQL,VOIP,Linux,Agile,SIP,Diameter,Test,Oracle,Software User Experience,Interaction Design,3D rendering,Event,Team,Graphic Design,Engineering,User Experience Design,Sales,3D Modeling,Product Marketing,Employee Training,business plan,3D,Business Development,Creative Problem Solving,Product Design,renewable energy,Electronics,news paper,Project Management,Product Development,Social Enterprise
Thanks
-
networkx find_negative_cycle parameters
What am I supposed to pass as the source parameter to the
find_negative_cycle()
method of the python networkx module? In the documentation it says to pass a list, but when I try to do so, I get the error:TypeError: unhashable type: 'list'
-
How to define a graph using a distance matrix in igraph? (R)
I have a distance matrix from N points that I'd like to use to create a fully connected graph between N nodes.
So far I've tried the
graph_from_adjacency_matrix
function, but if my distance matrix is:[,1] [,2] [,3] [1,] 0 10 3 [2,] 10 0 2 [3,] 3 2 0
then I create the graph:
g3 = graph_from_adjacency_matrix(dist_matrix, weighted=TRUE, mode="undirected")
But when I plot it, node 2 doesn't seem to be further from node 1 than node 3 is.
Is there a way to define the graph from this matrix and then plot it (with nodes closer to each other when the distance is smaller and vice versa)?
-
How to add URL hyperlink to nodes created in network graphs with plotly?
I have successfully created a 3D network graph using Plotly and igraph in python using this helpful link.
I want to manipulate those nodes meaning adding a hyperlink to each node so when I click on the nodes it should open that URL.
Does anyone have any idea if it's possible with plotly? If not any other suggestions would be appreciated. -
Edge Size in R based on frequency
Given a matrix with multiple edges (that is, the same two nodes are connected multiple times, over time), I'd like to be able to use the frequency of that edge occurring to calculate a weight for the visualization. is there a way to do this?
For example if the edge list came from:
#create dataset from<-c("a","a","a","b","b","c") to<-c("b", "b", "c", "a", "a", "a") df<-data.frame(from,to) # get names from.names <- df %>% select(from) %>% unique() %>% rename(name=from) to.names<- df %>% select(to) %>% unique() %>% rename(name=to) edge_names<- rbind(from.names, to.names) %>% unique %>% arrange(name) #create network nw<-graph_from_data_frame(df, vertices=edge_names, directed=F) #graph the network graph1<-ggraph(nw, layout="stress") + geom_edge_link(color="grey") + geom_node_point(aes(size =3))+ geom_node_text(aes(label=name, fontface="bold"), repel=T)+ theme_void() graph1 #show frequency of edges nw%>% as_adjacency_matrix()
then the resulting edge attributes should show a wider edge for a to b as this occurred twice, and a narrower edge for a to c as this occurred once. I'm using Igraph.
-
Using PyGraphviz (or other package) to create a study cohort flow diagram
I am attempting to use Python (and by extension PyGraphviz) to replicate the R code shown in the answer to this other question: DiagrammeR - arrow problems
I am very novice at Python and was wondering if anyone could give an example of what would need to change to generate a similar flow chart in Python/PyGraphviz? I am also open to using a different package if one exists.
This is an additional question but I am also wondering if it'd be possible to insert text strings into the diagrams labels. For example instead of hardcoding/writing "n = 500" in one of the boxes I'd like to be able to insert a text string that is calculated from a pandas dataframe.
So if the pandas dataframe has a indicator variable that 500 of the records meet, I'd like to be able to count these records from the dataframe and then insert that number as a string into the label, similar to how you can assign a string to an object in R using object <- as.character(nrow(dataframe))
-
neoviz client visualisation for neo4j - protect passwords
I'd like to use neoviz to visualise queries from neo4j, for public audience: https://github.com/neo4j-contrib/neovis.js/issues/245
I looked at open issues concerning security of neoviz: https://github.com/neo4j-contrib/neovis.js/issues/245
This is a beautiful post, but still a problem : cannot expose the credentials for accessing the db.
Here there is a comment to proxy the backend, but without an example: https://community.neo4j.com/t/protecting-neo4j-password-when-using-neovis/548
And here an answer that the security issue of the password exposed, has not been addressed: https://github.com/neo4j-contrib/neovis.js/issues/101
I am using a python backend (flask): can you show how to implement any practice for using neoviz in a web app for public use, and protect the credentials ?
If not neoviz, any other library that could show the same results as neoviz without any data transformation other than simply sending the returned subgraph as a json ?