Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: changing style of vertices for ShowGraph with Combinatorica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg86358] Re: changing style of vertices for ShowGraph with Combinatorica
  • From: Helen Read <hpr at together.net>
  • Date: Sun, 9 Mar 2008 05:03:26 -0500 (EST)
  • References: <fqqrql$k9j$1@smc.vnet.net> <fqtqek$cuk$1@smc.vnet.net>
  • Reply-to: HPR <read at math.uvm.edu>

Steve Luttrell wrote:
> 
> "Murray Eisenberg" <murray at math.umass.edu> wrote 
>> With Mathematica 6, I can change the default style (medium black disk)
>> for rendering the vertices of a Combinatorica Graph like this:
>>
>>   Needs["Combinatorica`"]
>>
>>   g = Cycle[3];
>>   ShowGraph[g, VertexStyle -> Disk[Large], VertexColor -> Red]
>>
>> But how can I, for example, change the vertex style so it is, say, a
>> large yellow disk with a thick red boundary?  Or even just change it to
>> be a circle?  I tried "obvious" things like the following, but they
>> cause errors:
>>
>>   ShowGraph[g, VertexStyle -> Graphics[Circle[], ImageSize -> 20]]
>
> You could use the native GraphPlot function to plot your 
> Combinatorica-defined graph as follows:
> 
> Needs["Combinatorica`"]
> 
> g = Cycle[3];
>
> GraphPlot[g,
>  VertexRenderingFunction -> ({EdgeForm[{Thick, Red}],
>      FaceForm[Yellow], Disk[#1, 0.05], Text[#2, #1]} &)]

The native GraphData knows all kinds of graphs, without the need for 
loading the Combinatorica package.

For instance, this plots the 3-cycle.

GraphData["TriangleGraph"]

If you want to format it with GraphPlot as Steve Lutrell suggests above, 
the documentation suggests getting the EdgeRules from the GraphData.

GraphPlot[GraphData["TriangleGraph", "EdgeRules"],
  VertexRenderingFunction -> ({EdgeForm[{Thick, Red}],
      FaceForm[Yellow], Disk[#1, 0.05], Text[#2, #1]} &)]

However -- and this goes to Murray's comment in another post about this 
being a little "half-baked" -- try the following.

GraphData["PetersenGraph"]  (* the "popular" rendering of the Petersen 
graph *)

GraphData["PetersenGraph", "AllImages"]  (* all available images of 
Petersen *)

Now try using the edge rules and plotting with some formatting in GraphPlot:

GraphPlot[GraphData["PetersenGraph", "EdgeRules"],
  VertexRenderingFunction -> ({EdgeForm[{Thick, Red}],
      FaceForm[Yellow], Disk[#1, 0.05], Text[#2, #1]} &),
  EdgeRenderingFunction -> ({Blue, Line[#1]} &)]

Now we get a different rendering of the Petersen graph. So we need to 
get the VertexCoordinateRules too:

pete = GraphData[
    "PetersenGraph", {"EdgeRules", "VertexCoordinateRules"}];

GraphPlot[pete[[1]], VertexCoordinateRules -> pete[[2]],
  VertexRenderingFunction -> ({EdgeForm[{Thick, Red}],
      FaceForm[Yellow], Disk[#1, 0.1], Text[#2, #1]} &),
  EdgeRenderingFunction -> ({Blue, Line[#1]} &)]

It would be nice if GraphData would accept formatting directly, so one 
would not need to stand on one's head to do this.

-- 
Helen Read
University of Vermont


  • Prev by Date: Re: Apply function to parts of a list
  • Next by Date: How to use Thread when second argument to function is a list of lists?
  • Previous by thread: Re: Re: changing style of vertices for ShowGraph with Combinatorica
  • Next by thread: Re: Opening notebooks with NotebookOpen when one of the directory