Why everytime that a script runs shows a different structure?
Like, the logic it´s the same but it shows diferent order, is there a way to keep the same seed or structure?
Examples of same data but different results:
You can save the position of the nodes in a variable so that the network is represented always in the same way:
First create the graph:
G1 = nx.barabasi_albert_graph(20, 2)
Then run the layout function:
pos = nx.spring_layout(G1)
Then draw the graph like this:
nx.draw(G1, pos=pos)
The nx.spring_layout and other layout functions also allow for a seed value:
nx.spring_layout(G1, seed=31415)
Please note that the order of the nodes in you graph may change each time you create your graph. This may be what is affecting the layout of the graph.
Try to run each function separately.
I want to draw two graphs are almost same, the only difference is that the second one will have some edges grayed out. And I want nodes in the second graph stay exactly where they are in the first graph.
You need to define the optional pos argument.
In your case using circular layout pos = nx.circular_layout(G). Then you call the plotting commands like nx.draw(G, pos, other_arguments...).
I'm pretty new to coding and I need to create a code that generates an object along the normal of a selected geo surface.
Anything to start me on the right path would be appreciated.
I initially tried to use duplicate, but I was told that command instancer is the better option.
def ChainmailSurfaceGenerator():
thing = MC.ls(sl=True)
print thing
if not thing:
MC.error("select a torus")
#create a group for your chainmail*
grp = MC.group(empty=True, name=thing[0] + '_grp#'
#create hierarchy of grouped toruses
MC.polyTorus( radius=1, n = 'chainmail_link')
MC.duplicate('chainmail_link')
#query the direction of UV normals off the face
#lessen the amount of geometry if its too dense
#try it out on a plane surface first
#keep things simple early
#what if chains don't connect perfectly? add a randomizer so that the chains aren't all completely symmetrical
#don't use MC.duplicate; use Instancer
You might not actually need to query the UV direction of the target geometry.
Try looking into the commands for constraints like cmds.normalConstraint or cmds.geometryConstraint. As for the number of objects to make, consider using a for loop in a range of how many objects you want. If you want to apply a random rotation, I would recommend using a group or a locator as an offset for transforming the group around (either with setAttr or xform) so that you can move the group while maintaining the ability to rotate the duplicate in it's y axis. If you go the route of normal constraints, be sure to use the aim flag to point the object up in its y axis! Googling the commands should come up with documentation on what flags to use.
Here is basic script I use for drawing:
from graph_tool.all import *
g = load_graph("data.graphml")
g.set_directed(False)
pos = sfdp_layout(g)
graph_draw(g, pos=pos, output_size=(5000, 5000), vertex_text=g.vertex_index, vertex_fill_color=g.vertex_properties["color"], edge_text=g.edge_properties["name"], output="result.png")
Main problems here are ugly edge text and vertexes that are too close to parent. As I understand this happens because by default fit_view=True and result image scaled to fit size. When I set fit_view=False result image doesn't have graph (I see only little piece).
Maybe I need another output size for fit_view=False or some additional steps?
Today I ran into the same problem.
It seems that you can use fit_view=0.9, and by using a float number yo can scale the fit. In that case it would appear 90% than the normal size. If you use 1, will be the same size.
Hope it helps.
I encountered a problem when trying to plot a graph with many nodes using NetworkX and graphviz_layout. More specifically, the arguments that pass into nx.graphviz_layout do not help at all. Attached is the code I use:
G=some_graph()
import matplotlib.pyplot as plt
plt.figure(figsize=(32,32))
# use graphviz to find radial layout
pos=nx.graphviz_layout(G,prog="dot",
root=1000,
args='-splines=true -nodesep=0.6 -overlap=scalexy'
)
nx.draw(G,pos,
with_labels=True,
alpha=0.5,
node_size=600,
font_size=10
)
plt.savefig("imagenet_layout.png")
No matter how I change "args" in nx.graphviz_layout, the output image would be the same, and all nodes overlap with each other. Could anybody help me with this? Thanks!
For me it seems that in order to give args to the prog you need to use the format '-G' +'argsname=x'. I noticed in the example they give the docs the arg epsilon asG.draw(‘test.ps’,prog=’twopi’,args=’-Gepsilon=1’). So I tried out that pattern as shown below. I just added G in front of the arguments. Now, these arguments vary quite a bit depending on what prog you use, so you definitely want to use 'dot' for what you want to accomplish. You can see all the possible arguments and how they work with each prog here. For my porpoises, I needed to have the nodesep=0.01.
G=some_graph()
import matplotlib.pyplot as plt
plt.figure(figsize=(32,32))
# use graphviz to find radial layout
pos=nx.graphviz_layout(G,prog="dot",
root=1000,
args='-Gsplines=true -Gnodesep=0.6 -Goverlap=scalexy'
)
nx.draw(G,pos,
with_labels=True,
alpha=0.5,
node_size=600,
font_size=10
)
plt.savefig("imagenet_layout.png")
Here is a comparison of my graph with and without the args, with code. First without the args.
A = nx.nx_agraph.to_agraph(G) # convert to a graphviz graph
A.layout(prog='neato') # neato layout
#A.draw('test3.pdf')
A.draw('test3.png' )
With args
A = nx.nx_agraph.to_agraph(G) # convert to a graphviz graph
A.layout(prog='dot') # neato layout
#A.draw('test3.pdf')
A.draw('test3.png',args='-Gnodesep=0.01 -Gfont_size=1', prog='dot' )
SO you can see that the images are different once I got the args to work.
My reading of the documentation for pygraphviz suggests that overlap does not work with dot.
For nodesep :
In dot, this specifies the minimum space between two adjacent nodes in the same rank, in inches.
It's not clear if the overlaps you are observing are between nodes in the same rank or between the ranks. If it is just between ranks, you may want to modify ranksep.
I do see that you are setting the positions, and then later you set the nodesize, and you are making node_size quite a bit larger than the default (600 vs 300). Since it does not know what node_size you are going to use when it finds pos, using a large enough node_size will cause overlap.
So I would recommend setting node_size to be the default, and if overlap remains, setting node_size to be smaller. If you're having issues with the between or within rank separations being out of proportion, then play with ranksep and nodesep.
About “overlap”,do you mean there are nodes drawed last time in current output? If so, add "plt.clf()"after"plt.savefig(****)"!
About the node_size, the default is 300, but the unit is not given in the document. I am using networkx these days too, can you tell me the unit if you know that?