Networkx pygraphviz graphviz_layout arguments not working - python

I have a graph built with networkx and graphviz in Python using pygraphviz and networkx's graphviz_layout it is then displayed in Plotly.
I wish to change the space between nodes of the graph.
I currently have the graph displayed in plotly like this:
However, when I try to use args on the graph to change the distance between nodes like so:
pos=graphviz_layout(G,prog='dot',args='-Gnodesep="10.0" -Granksep="1.0"')
I do not see any changes on the plotly plot. Am I doing something wrong with the args?

Related

How to draw fractal graph in networkx library?

I need to draw fractal graph or self-similar graph (for example like in picture below)
Does the networkx library have a special function for constructing this graph?

Create a network graph with curved edges using plotly networkx

I m trying to make an interactive graph on plotly, where I first create the network graph using networkx, and then graph it with plotly so that it can be hosted and be interative and shared, very similar to what's described here: https://plotly.com/python/network-graphs/
I would like to make the edges curved -- in networkx I can do this with connectionstyle="arc3,rad=-0.3". How do I do this in Plotly?
My main problem is that edges are overlapping, I want to remove that overlapping if there is any better option please suggest but restricted to plotly only.
I searched in documentations of go.scatter too but didn't found anything relevant to my query.

Is there a way to make a network graph in plotly with curved edges?

I'm trying to make an interactive graph on plotly, where I first create the network graph using networkx, and then graph it with plotly so that it can be hosted and be interative and shared, very similar to what's described here: https://plotly.com/python/network-graphs/
I would like to make the edges curved -- in networkx I can do this with connectionstyle="arc3,rad=-0.3". How do I do this in Plotly?

Add graphviz plot inside matplotlib

I am visualizing various networks with networkx. Take a look at simple example
graph = nx.DiGraph()
graph.add_edge("a", "b")
graph.add_edge("a", "a")
nx.draw(graph)
plt.show()
Unfortunately, networkx plotting does not render self loops. I am aware of other feature rich packages like GraphViz and its implementation pygraphviz. However, such packages do not allow me to customize my plots (like subplots, annotations etc). I can do all of these with networkx as it can plot with matplotlib Axes. Which is very convenient for programmatic manipulations and heavy customizations. Is there way to get network plotting of GraphViz to matplotlib?
I can always embed PNG created by GraphViz into matplotlib plots using imshow. However, its results are horrible with little customization control.
It doesn’t seem like this exists yet. If you want to implement it yourself, there are a few options. If you want to leave the layout to Graphviz and just hand shapes and positions to Matplotlib, two options remain to get the data necessary for rendering:
You use the binaries (like dot) with the -Tjson option, which seems to emit all necessary data for drawing, but I didn’t find documentation for what e.g. the ops are.
You Use Graphviz as a Library. Section 2.3 (Rendering the graph) describes how to access the data.
You then feed this data into the Axes’ Artist (tutorial). Matplotlib also has a tutorial for how to draw paths.
I am not sure why you say networkx does not render self-loops. Isn't this what you are looking for?
import networkx as nx
from matplotlib import pyplot as plt
graph = nx.DiGraph()
graph.add_edges_from([("a", "b"), ("a", "a"), ("b", "b"), ("c", "b"), ("c", "c")])
nx.draw(graph, with_labels=True)
plt.show()

How to draw multiple edges between same set of nodes in PyGraphviz? [duplicate]

I try to draw multigraph in Python using graphviz.
For now I can draw usual graphs in Python somehow like:
import pygraphviz as pgv
G=pgv.AGraph()
G.add_node('a')
G.add_node('b')
G.layout()
G.add_edge('a','b','first')
G.add_edge('a','b','second')
sorted(G.edges(keys=True))
G.draw('file.png')
And I get on the output:
But actually I want get multigraph, i.e.
But documentation stays that it should differentiate :
I have no idea about drawing multigraph but not just graph.
Thanks for any help.
Addition:
it seems that there are no yet such libraries in python that can do it, so I did it using Wolfram Mathematica. But question is still opened.
Addition
Now working code looks so:
import pygraphviz as pgv
G=pgv.AGraph(strict=False)
G.add_node('a')
G.add_node('b')
G.layout()
G.add_edge('a','b','first')
G.add_edge('a','b','second')
sorted(G.edges(keys=True))
G.draw('file.png')
As the documentation you quoted says, you need to specify strict=False when creating a multi-edge graph. Since you didn't do this your graph doesn't support parallel edges.

Categories

Resources