>>> import matplotlib.pyplot as plt
>>> import networkx as nx
>>> G=nx.grid_2d_graph(4,4)
>>> nx.draw(G);
>>> plt.show();
The code above draws the gird of nodes but produces it in a tilted
way.Also it changes the position of nodes every time I rerun code.How
can i draw nodes having fixed position of nodes and grids every time
i draw it
Regards,
Khalid
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.
For grid_graph() the node labels can be used as positions.
So you can write this:
import networkx as nx
import matplotlib.pyplot as plt
G = nx.grid_2d_graph(10,8)
pos = dict(zip(G,G)) # dictionary of node names->positions
nx.draw(G,pos,with_labels=False)
plt.show
Aric
That is a matplotlib question - you can try adding this line (before show)
plt.setp(plt.gca(), 'ylim', list(reversed(plt.getp(plt.gca(), 'ylim'))))
which is what is suggested here:
http://www.mail-archive.com/matplotl...@lists.sourceforge.net/msg04291.html
Aric
On Nov 23, 4:05 pm, Aric Hagberg <aric.hagb...@gmail.com> wrote:
> On Wed, Nov 23, 2011 at 4:57 PM, Khalid chaudhry <khalidch...@gmail.com> wrote:
> > Thanks Aric and Anupama
> > Aric,
> > Super cool stuff.The provided code(i changed "with_labels=True") displays
> > nodes labels with (0,0) starting from bottom left.How can i label the nodes
> > so that first node with (0,0) label starts from top left.
>
> That is a matplotlib question - you can try adding this line (before show)
> plt.setp(plt.gca(), 'ylim', list(reversed(plt.getp(plt.gca(), 'ylim'))))
> which is what is suggested here:
> http://www.mail-archive.com/matplotlib-us...@lists.sourceforge.net/msg04291.html
> Aric