Python Forum
Python Networkx: Visualize an edge weight with a bubble/circle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Networkx: Visualize an edge weight with a bubble/circle
#1
Hello

I am trying to plot a network in python using networkx. on the edges there should be circle or bubbles with sizes according to the weight of the edges. Lets say I have the nodes A, B, C, D

the edges an their weigths (w):
A->B, w=1
A->C, w=1
A->D, w=2
B->C, w=3
B->D, w=2
C->D, w=4

and this is what I want to have:
   

Is there any possibility to do that? Or do you have any suggestion how to do that?

This is my code by now, but i was only able to change the edge width, but not to put circles/bubbles on the edge:

import networkx as nx
import matplotlib.pyplot as plt

G = nx.Graph()
G.add_node('A', pos=(0,5))
G.add_node('B', pos=(3,12))
G.add_node('C', pos=(3,6))
G.add_node('D', pos=(7,-4))
weights = [1, 1, 2, 3, 2, 4]
G.add_edge('A', 'B', weight=weights[0])
G.add_edge('A', 'C', weight=weights[1])
G.add_edge('A', 'D', weight=weights[2])
G.add_edge('B', 'C', weight=weights[3])
G.add_edge('B', 'D', weight=weights[4])
G.add_edge('C', 'D', weight=weights[5])
pos=nx.get_node_attributes(G,'pos')

labels = nx.get_edge_attributes(G, 'weight')
nx.draw(G, pos)
nx.draw_networkx_edges(G, pos, width=weights)
nx.draw_networkx_edge_labels(G, pos, edge_labels=labels)

plt.show()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Weight Distribution 11drk9 11 704 Mar-13-2024, 06:08 AM
Last Post: Pedroski55
  I am getting a valueError. And not sure why? My goal is to visualize the correlation ReadytoCode 0 486 Dec-11-2023, 05:33 AM
Last Post: ReadytoCode
  Convert np Array A to networkx G IanAnderson 2 698 Jul-05-2023, 11:42 AM
Last Post: IanAnderson
  'networkx' Questions Trader 0 760 Dec-29-2022, 10:20 PM
Last Post: Trader
  networkx package is not visible in singularity container image erdemath 11 2,310 Oct-14-2022, 12:04 PM
Last Post: Larz60+
  How to plot seaborn heatmap on top of a background circle SriRajesh 0 1,426 Jul-09-2022, 04:00 AM
Last Post: SriRajesh
  Help with basic weight converter PythonSquizzel 3 1,424 Jun-29-2022, 02:42 PM
Last Post: deanhystad
  drawing moving circle on line with python barrai 1 3,146 Feb-25-2022, 03:33 PM
Last Post: BashBedlam
  Program to move a dot towards a circle center plumberpy 10 4,233 Dec-03-2021, 12:20 PM
Last Post: BashBedlam
  Draw circle from GPS coords, and get GPX file? Winfried 0 2,187 Mar-29-2021, 07:19 PM
Last Post: Winfried

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020