Friday, January 27, 2012

drawing sexy graphs in matlab

Everybody who loves computer sciences loves graphs.  But the fat 'n juicy graphs, the ones with complex structure you just gotta visualize.  To enjoy these beautiful data structures, the hackers at AT&T gave us, the world, Graphviz as a powerful tool for visualizing complex graphs in two dimensions.  I do a lot of stuff in Matlab, so I've put my simple graphviz matlab wrappers up on Github so everybody can enjoy them. I do a lot of stuff with graphs...

My repository, which I'm already using as a submodule in many of my projects, can be found here:
https://github.com/quantombone/graphviz_matlab_magic

Here is a matlab script (included as a Github gist), which should be ran in an empty directory, and it will download a nice mat file plus clone my repo and show the following nice graph.  I perform two graphviz passes where the first one is used to read the graphviz coordinates (from the sfdp embedding) and use Matlab's jet colormap to color the edges based on distances in this space.  In other words, nearby nodes which are connected will be connected by red (hot) edges and faraway nodes will be connected by blue (cold) edges.



The matrix visualized comes from an electromagnetic model, the details can be found here: http://www.cise.ufl.edu/research/sparse/matrices/Bai/qc324.html

The original picture generated by Yifan Hu is here for comparison:

Enjoy
--Tomasz

5 comments:

  1. Anonymous7:37 PM

    Thanks so much for releasing this. Very useful& works like magic.

    ReplyDelete
  2. Anonymous6:41 AM

    Thanks a lot for releasing this. How is it different from the following interface?
    http://www.mathworks.com/matlabcentral/fileexchange/4518

    ReplyDelete
  3. Anonymous4:49 PM

    This is awesome. Thank you.

    ReplyDelete
  4. Anonymous2:08 PM

    Hi,

    It seems that the script is not really working for me. I sometimes get an empty graph when there should be edges. Does the matrix need to fulfill certain requirements? All my matrices are symmetric matrices. Thank you very much!

    ReplyDelete
  5. I just tried, and it worked for me. I suggest you make sure your graphviz installation is working properly before using the matlab wrappers.
    --Tomasz

    ReplyDelete