Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6903423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:55:25+00:00 2026-05-27T07:55:25+00:00

I am generating Random Geometric Graph and storing node and edges information using write_adjlist

  • 0

I am generating Random Geometric Graph and storing node and edges
information using write_adjlist into file.

Code: python1.py

G=nx.random_geometric_graph(10,0.5) 
filename = "ipRandomGrid.txt" 
fh=open(filename,'wb') 
nx.write_adjlist(G, fh) 
nx.draw(G) 
plt.show()

Now from the second file I am trying to generate the graph with the
same node and edges information. I am using read_adjlist to find the
information.

Code: python2.py

filename = "ipRandomGrid.txt" 
fh=open(filename, 'rb') 
G=nx.Graph() 
G=nx.read_adjlist("ipRandomGrid.txt") 
pos=nx.random_layout(G) 
nx.draw_networkx_nodes(G,pos,nodelist=[1,2],node_color='b') 
nx.draw(G) 
plt.show()

It’s showing me below error.

raise nx.NetworkXError('Node %s has no position.'%e) 
networkx.exception.NetworkXError: Node 1 has no position. 

I think the problem is with the pos variable. Can some one help me to
solve this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:55:26+00:00Added an answer on May 27, 2026 at 7:55 am

    Consider the following interactive session:

    >>> import networkx as nx
    >>> G = nx.random_geometric_graph(10, 0.5)
    >>> with open("junk.txt", "wb") as f:
    ...   nx.write_adjlist(G, f)
    ...
    >>> G.nodes()
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    >>> with open("junk.txt", "rb") as f:
    ...   G2 = nx.read_adjlist(f)
    ...
    >>> G2.nodes()
    [u'1', u'0', u'3', u'2', u'5', u'4', u'7', u'6', u'9', u'8']
    >>>
    

    When reading the node list from the file, the nodes identities are treated as strings, not as numbers. Thus, you’re getting an error because you’re trying to plot two non-existent nodes 1 and 2. Change them to strings ('1' and '2') and it should work fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am generating random Geometric graph using networkx. I am exporting all the node
I am generating the random numbers in a domain by using the following code.
I’m generating multiple, random sized, circular elements using the Raphael JavaScript library but because
Is there a difference between generating multiple numbers using a single random number generator
I have following code that is generating random no. between 1 to 10. This
Right now I'm generating a random enumerator using boost's random library. Basically I'm using
I'm generating a random 10 character string with php, and inserting it into a
So I'm generating a random number using Rnd and Randomize to set a seed
Possible Duplicate: generating random numbers from skewed normal distribution i expect a long array
I'm looking for tools for generating random but realistic text. I've implemented a Markov

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.