Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - matplotlib - weighted graphs

Is it possible to plot weighted graphs in python using matplotlib?. I did not find it on the matplotlib website.

if I can't do it using matplotlib, can I do it using something else? can we do it on libreoffice?

essentially this is how my data looks like.

a,b,5
b,c,10
a,c,7
like image 429
rnish Avatar asked Apr 28 '26 13:04

rnish


1 Answers

Got the answer: The link points us an answer given by William Stein. all credits to him.

Here is the answer:

Try Sage - it's open source and can draw weighted directed graphs. For example:

A = random_matrix(ZZ,6, density=0.5)
G = DiGraph(A, format='weighted_adjacency_matrix')  # graph from matrix
H = G.plot(edge_labels=True, graph_border=True)
H.show()             # display on screen
H.save('graph.pdf')  # save plot to vector pdf for inclusion in a paper

Here is another given in the same page by : Nick Loughlin

Try Graphviz - it's open source and quite flexible as far as usage is concerned.

It's good at automatic layouts etc, where for example Maple would make a mess of things.

like image 78
rnish Avatar answered May 01 '26 03:05

rnish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!