Prev: Import of CSDF files
Next: Map vs. Table
From: alexxx.magni on 22 Mar 2007 02:27 greetings, after having used for some time a very powerful program (Graphviz) for displaying the graph structures I'm working on, I decided to give it a try under Mathematica, since I use M. for many other related tasks. I started from DiscreteMath`GraphPlot`, but from what I can see everything is done using an adjacency matrix composed of (0,1)'s, right? That is, my problem is that I need to LABEL the vertices with a name, instead of a position. >From http://documents.wolfram.com/mathematica/functions/AdvancedDocumentationGraphPlot I thought for a moment it was possible (e.g. see graph under "MaximalBipartiteMatching" with Tom,Rob,Adam etc), but I then realized it was demonstration-only, and no code is present to do it am I right, or there is a way? thanks for any help... Alessandro Magni
From: Chris Chiasson on 23 Mar 2007 20:05 This is possible. GraphPlot adds additional functionality to the graphics function Text. Instead of a position, you can give an integer that corresponds to a graph node number. I used that functionality in this package: http://bond-graphs.googlecode.com/svn/trunk/BondGraphs/BondGraphs.nb Take a look at the definition of BondGraphPlot, specifically the option for VertexStyle that is fed to GraphPlot. I personally have a hard time making Mathematica 5.2 draw nice directed graphs. It certainly isn't a replacement for Visio. On the other hand, neither is Graphviz. 1. It is difficult to specify that the arrows between nodes should end or begin at a non-circular a bounding box border. 2. It would be nice to see more options for the node layout algorithms & edge routing. On 3/22/07, alexxx.magni(a)gmail.com <alexxx.magni(a)gmail.com> wrote: > greetings, > after having used for some time a very powerful program (Graphviz) for > displaying the graph structures I'm working on, I decided to give it a > try under Mathematica, since I use M. for many other related tasks. > > I started from DiscreteMath`GraphPlot`, but from what I can see > everything is done using an adjacency matrix composed of (0,1)'s, > right? > That is, my problem is that I need to LABEL the vertices with a name, > instead of a position. > >From http://documents.wolfram.com/mathematica/functions/AdvancedDocumentationGraphPlot > I thought for a moment it was possible (e.g. see graph under > "MaximalBipartiteMatching" with Tom,Rob,Adam etc), but I then realized > it was demonstration-only, and no code is present to do it > > am I right, or there is a way? > > thanks for any help... > > Alessandro Magni > > > -- http://chris.chiasson.name/
From: dh on 23 Mar 2007 20:11 Hi Alessandro, this can e.g. be done withthe "VertexStyleFunction" options. E.g.: In[35]:= labels = Table[StringJoin["Label", ToString[i]], {i, 12}]; GraphPlot[{1 -> 2, 2 -> 3, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 8, 8 -> 1, 1 -> 9, 2 -> 9, 3 -> 10, 4 -> 10, 6 -> 11, 5 -> 11, 7 -> 12, 8 -> 12}, "EdgeStyleFunction" -> (Arrow[{#1, #2}] & ), "VertexStyleFunction" -> ({Text[labels[[#1]], #1]} & )] Daniel alexxx.magni(a)gmail.com wrote: > greetings, > after having used for some time a very powerful program (Graphviz) for > displaying the graph structures I'm working on, I decided to give it a > try under Mathematica, since I use M. for many other related tasks. > > I started from DiscreteMath`GraphPlot`, but from what I can see > everything is done using an adjacency matrix composed of (0,1)'s, > right? > That is, my problem is that I need to LABEL the vertices with a name, > instead of a position. >>From http://documents.wolfram.com/mathematica/functions/AdvancedDocumentationGraphPlot > I thought for a moment it was possible (e.g. see graph under > "MaximalBipartiteMatching" with Tom,Rob,Adam etc), but I then realized > it was demonstration-only, and no code is present to do it > > am I right, or there is a way? > > thanks for any help... > > Alessandro Magni > >
From: danl on 23 Mar 2007 20:33 alexxx.magni(a)gmail.com wrote: > greetings, > after having used for some time a very powerful program (Graphviz) for > displaying the graph structures I'm working on, I decided to give it a > try under Mathematica, since I use M. for many other related tasks. > > I started from DiscreteMath`GraphPlot`, but from what I can see > everything is done using an adjacency matrix composed of (0,1)'s, > right? > That is, my problem is that I need to LABEL the vertices with a name, > instead of a position. > >From http://documents.wolfram.com/mathematica/functions/AdvancedDocumentationGraphPlot > I thought for a moment it was possible (e.g. see graph under > "MaximalBipartiteMatching" with Tom,Rob,Adam etc), but I then realized > it was demonstration-only, and no code is present to do it > > am I right, or there is a way? > > thanks for any help... > > Alessandro Magni I received the following response from Yifan Hu, who is the developer at WRI responsible for GraphPlot. Daniel Lichtblau Wolfram Research ------------------- One way to do what you want is GraphPlotLabeled[g_, opts___?OptionQ] := Module[ {vtx, coord}, Needs["DiscreteMath`GraphPlot`"]; vtx = VertexList[g]; coord = GraphCoordinates[g, opts]; GraphPlot[g, VertexStyleFunction -> (Text[vtx[[#]], coord[[#]], Background -> Yellow] &)]]; GraphPlotLabeled[{"a" -> "b", "b" -> "c", "c" -> "d", "d" -> "a", "a" - > "c"}] post a sample of your graph would help to figure out how to help you better. -------------------
From: Frank Iannarilli on 5 Apr 2007 04:22
On Mar 22, 2:27 am, "alexxx.ma...(a)gmail.com" <alexxx.ma...(a)gmail.com> wrote: > I started from DiscreteMath`GraphPlot`, but from what I can see > everything is done using an adjacency matrix composed of (0,1)'s, > right? Perhaps the other responders have settled your need, but if you wish to more flexibly represent your graph (e.g., as list of unordered pairs, etc etc) instead of the adjacency matrix straightjacket, you might look at the facilities in Combinatorica (a standard add-on package). The package also appears to support decent automatic graph rendering via so-called "embedding" options, one of which is the spring model. Combinatorica also has its own website, along with a book one can purchase, although I surmise you can address your problem without book purchase :-) Cheers. |