I have defined a graph by using from pyvis.network import Network and defining a network as net = Network().
I added to the net edges and nodes using the functions net.add_nodes(nodes) and net.add_edge(x, y). There is any chance to deal with this graph not only using a visualization? So for e.g. to find all paths between two specific nodes? Because searching in the documentation there is only the possibility to plot the graph. I saw other options (e.g. class) to deal with graphs (example) but is very annoying to define the graph with a dict of a dict.
From the pyvis documentation:
The pyvis library is meant for quick generation of visual network graphs with minimal python code. It is designed as a wrapper around the popular Javascript visJS library found at this link.
You probably want a library such as networkx, which you probably have tagged by accident. It's description states
NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.
This includes many operations, see the tutorial or to take your example: shortest path
Related
are there any tools or examples for how to visualize things like linked lists and decisions trees using matplotlib?
I ask because I wrote a linked list type of class (each node can have multiple inputs/outputs, and there's a class variable that stores node names), and want to visualize it. Unfortunately, my computer at work is locked down so much that I can't download other packages, so I've got to use whatever is on hand- which is matplotlib
I've started reading it, and if I do it by hand, I can probably make something that visualizes one-directional linked lists (just give it the root node, and plop down a square with text for each operation). But if there's branching, or multiple inputs into a node things get a bit more complicated- for example is it possible to expand a figure after creating it?
Yes, you can use networkx library and the draw_networkx method. There are plenty of examples on Stack Overflow. Here is one example: https://stackoverflow.com/a/52683100/6361531
Is there any python library with functions to perform fixed or random effects meta-analysis?
I have search through google, pypi and other sources but it seems that the most popular python stats libraries lack this functionality.
It would be great if it also provide graphical solutions to produce funnel plots and forest plots.
Forest plot example:
It thought of something similar to R package rmeta
I've found some people creating their own functions manually, but it isn't a actual library. In addition, metasoft was promising, but it uses python only to convert between formats.
Just to say, it seems the mostly widely used tool is R's metafor, which provides seemingly every possible method used and includes essential plotting functions.
In Python, PythonMeta the backend for a web-based tool PyMeta which offers many of the methods (fixed and random effects, various data types) found in metafor.
This PyMARE project is still under development but does provide various fixed and random effects meta-analysis estimators (this is a spin-off from the rather more mature NiMARE tool for neuroimaging meta-analysis).
statsmodels now also offers some options for meta-analysis and visualization of its results, more information here:
https://www.statsmodels.org/devel/examples/notebooks/generated/metaanalysis1.html
I have just found out about GephiStreamer. https://pypi.python.org/pypi/GephiStreamer
Using this package one can send instructions from python to Gephi to create nodes and edges in Gephi.
# Create a node with a custom_property
node_a = graph.Node("A",custom_property=1)
# Create edge
edge_ab = graph.Edge(node_a,node_b,custom_property="hello")
stream.add_edge(edge_ab)
Similarly I want to do everything in Gephi through Python. Here is what I typically do.
ex:
steps:
load nodes
load edges
calculate betweeness centrality
change the size/color of nodes as per their centrality scores
change the graph layout (such as forceatlas2)
give the output graph
Below is the output I have got manually, but I want to produce the same by sending instructions from python to Gephi. Documentation doesn't tell anything beyond creating nodes, edges and graphs.
I have also found out about NetworKit. https://networkit.iti.kit.edu/data/uploads/docs/NetworKit-Doc/python/html/gephi.html
This is slightly better than gephistramer, but this requires python 3.4 or higher and most of the packages like pandas, numpy or sickit are in 2.7.
also Is there a way to send the file I have created in gephi back to python.
Please suggest.
PS: I have edited the entire question details so that it's easier to understand now (hopefully).
I found this question while looking for the answer myself. I picked Gephi as my visualizer and then wanted to build a graph that was well supported by the tool by pulling data from around my org with Python.
I found GephiStreamer and it looks a simple yet comprehensive way to build graphs in Gephi from an external python environment (command line, or IDE)
The other options at this point are:
The Gephi Python Scripting Console
Any Graph Lib that can export in a Gephi readable format
NetworkX
python-igraph
graph-tool
Any of the python GEFX writers (Google "python GEFX")
There is no simple answer to that. The people at the Facebook group might be knowing something but IMO the best way to do it would be to call the Gephi toolkit, i.e. the available jar, from jython, check here for an example use. The thing is that jython doesn't allow to install numpy and a series of other libraries but I guess you could get around this issue by piping the output of one script to the other or using a queue like Celery.
So I would write a script let's call it graph_construction.py that uses networkx, construct the graph and then write it in the standard output in gexf. Then I would write a second script, gephi.py that would execute things in gephi and let's say write the graph to a pdf and then do something like:
python graph_construction.py | jython gephi.py output.pdf
and pray for it to work.
I need some graph algorithms for a project. I could implement them from scratch, but before I do so I wanted to see if there was something out there that I could use. I've looked at networkx and igraph. Networkx turns out to be memory inefficient for the size of the graphs I have to deal with. I think I'm using igraph incorrectly because it seems to just hang. I'll get more information on igraph if anyone's interested.
Networkx seemed promising because it is implemented in pure Python. The problem is that building the graph eats up all the memory. I have the graph in an SQLite database as an adjacency list.
So what I wanted to do was modify the code so that it can work directly with the SQLite representation instead of the networkx representation. Has anybody ever tried this successfully?
If that does not work, it goes back to the question in the title. Are there any graph implementations in Python that are reasonably decoupled from the graph representation?
I want to implement a driving direction in Python using something like Djikstra's shortest path. The algorithm requires the data to be represents in graph structure. Raw GIS data (e.g. shape files or OpenStreetMap data, however, represent their data differently. Therefore, I was wondering is there any Python library that can convert GIS data to graph structure?
In Java I found that GeoTools has exactly what I described. Is there any similar library in Python?
Haven't used it yet, but there's a function that generates directed graphs from shapefiles in Networkx: http://networkx.lanl.gov/reference/readwrite.nx_shp.html. If it doesn't do exactly what you need, it might suggest a solution. Uses OGR's Python bindings to read data.
See also Graphserver http://bmander.github.com/graphserver/.