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 6882699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:17:16+00:00 2026-05-27T05:17:16+00:00

I am generating random Geometric graph using networkx. I am exporting all the node

  • 0

I am generating random Geometric graph using networkx. I am exporting all the node and edges information into file.
I want to generate the same graph by importing all the node and edges information from file.

Code to export the node values and edge information.

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()

I am trying to export it with below code and trying to change the color of some nodes. But it is generating different graph.

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()

How to generate the same graph with few changes in color of some nodes?

  • 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-27T05:17:16+00:00Added an answer on May 27, 2026 at 5:17 am

    If I understand the problem you’re having correctly, the trouble is here:

    pos=nx.random_layout(G) 
    nx.draw_networkx_nodes(G,pos,nodelist=['1','2'],node_color='b') 
    nx.draw(G) 
    

    You create a random layout of the graph in the first line, and use it to draw nodes '1' and '2' in the second line. You then draw the graph again in the third line without specifying the positions, which uses a spring model to position the nodes.

    Your graph has no extra nodes, you’ve just drawn two of them in two different positions. If you want to consistently draw a graph the same way, you need to consistently use the pos you calculated. If you want it to be the same after storing and reloading, then save pos as well.

    • 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 and storing node and edges information using write_adjlist
Possible Duplicate: Java: generating random number in a range I want to generate a
Possible Duplicate: Generating random numbers in Javascript Hi.. I want to generate random numbers
I am generating 10 random floats between 6 and 8 (all for good reason),
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 am generating random password. but i want to get phonetic string of the
Possible Duplicate: Generating Random Numbers in Objective-C How do I generate a random number
Possible Duplicate: Java: generating random number in a range How do I generate a
Right now I'm generating a random enumerator using boost's random library. Basically I'm using

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.