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

  • SEARCH
  • Home
  • 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 8973925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:33:37+00:00 2026-06-15T18:33:37+00:00

I am trying to plot a graph from a distance matrix. The code works

  • 0

I am trying to plot a graph from a distance matrix. The code works fine and gives me an image. The image is big but all the nodes are packed together. I want increase the space between the nodes.
I want the nodes to be more apart not enlarged.

I tried Graphviz NEATO, But the problem with it is that it supports only 100 nodes, Since I have 1000 nodes, it was showing 10 clusters of 100 nodes each.

My overall code –

import networkx as nx
import pickle
import matplotlib.pyplot as plt
print "~~~Unpickle."
p_file = open('pickles/names')
Names = pickle.load(p_file)
p_file.close()
p_file = open('pickles/distance')
Dist = pickle.load(p_file)
p_file.close()

G = nx.Graph()

print "~~~Inserting Nodes."
for store in Names:
    G.add_node(store)

print "~~~Inserting Edges."

for i in range(601):
    for j in range(601):
        if Names[i]!=Names[j]:
            G.add_edge(Names[i],Names[j],weight=Dist[i][j])
print "~~~Drawing Graph."
nx.draw(G,pos,node_color='#A0CBE2',edge_color='none',width=1, edge_cmap=plt.cm.Blues, with_labels=False)
print "~~~Saving Figure."
plt.savefig("graph.png", dpi=500, facecolor='w', edgecolor='w',orientation='portrait', papertype=None, format=None,transparent=False, bbox_inches=None, pad_inches=0.1) 
print "~~~Success!"

Output (edges and labels removed) :
enter image description here

Output of Graphvix NEATO with 600 Nodes –

enter image description here

  • 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-06-15T18:33:38+00:00Added an answer on June 15, 2026 at 6:33 pm

    From figure documentation:


    figure(num=None, figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k')

    So figure(figsize=(10,10)) creates an 10 inch -by- 10 inch image, which will be 800-by-800 pixels.

    If you want to print a large network graph, the easiest way is to increase DPI.

    Try something like:


    plt.figure(num=None, figsize=(10, 10), dpi=1200). This will produce a large image file.

    You can also try printing pdf


    plt.savefig("graph.pdf")

    Using this option, the final graph is will not be rasterized.

    To change the distance between nodes you can make the nodes smaller or change the layout. Changing
    the layout is hard to do well.

    Try the scale option in layout
    for example,


    scale = 2

    will double distance between all nodes.

    So in your example, change the line


    nx.draw(G)

    to

    pos = nx.circular_layout(G, scale=2)
    nx.draw(G, pos)
    

    You can also use different layouts see documentation for more details.

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

Sidebar

Related Questions

I am trying to plot a graph with data from several worksheets into the
I have written the following code to plot a graph but it is not
I am trying to plot a graph using gnuplot. I have six text files.
So I'm trying to create some graphs using Core Plot, but for the following
Hi I am trying to plot this using matplotlib's step function from matplotlib.pyplot import
I'm (trying to) using JSON with PHP. I want to plot a graph using
I am trying to plot the elements from a list of lists, specifically coloring
I am trying to output multiple density plot from a function, by dividing the
I have 20 milliion rows in my table.I am trying to plot graph for
Here is my code: I am trying to get the CSV files from a

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.