MathGroup Archive 2010

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

Search the Archive

Re: Changing Graph style

  • To: mathgroup at smc.vnet.net
  • Subject: [mg114437] Re: Changing Graph style
  • From: Jaebum Jung <jaebum at wolfram.com>
  • Date: Sat, 4 Dec 2010 06:14:44 -0500 (EST)

Or you could use HighlightGraph to change option for now.  
For example,

convertGraphOption[g_, opt___?OptionQ] := HighlightGraph[g, {}, opt]

g = CompleteGraph[5]

convertGraphOption[g, GraphStyle -> "SimpleLink", VertexStyle -> Red]

 Jaebum


----- Original Message -----
From: "Yaroslav Bulatov" <yaroslavvb at gmail.com>
To: mathgroup at smc.vnet.net
Sent: Friday, December 3, 2010 4:21:35 AM
Subject: [mg114437] [mg114403] Re: Changing Graph style

It seems new Graph objects are immutable.
Brett Champion suggested creating a new graph from the old one by
copying the old options and adding new ones. I'm not sure if there's a
generic way to copy all options from the old graph, but here's a
version that works for options describing vertex positioning.
http://stackoverflow.com/questions/4301833/new-graph-in-mathematica-8-0

I agree that having two Graph object is a little confusing. Some graph
functions like MinimumSpanningTree exist only in Combinatorica, while
all the vertex centrality related functions are for the new Graph. To
use all of Mathematica's graph functionality, one needs to convert
between System`Graph and Combinatorica`Graph objects. Has anybody
implemented such a routine?

I ended up using the following routine when I need to turn a Graph
object into Graph with vertex labels

(* converts graph to labeled *)
convLabeled[g_] := Module[{coords}, (
    coords =
     PropertyValue[{g, #}, VertexCoordinates] & /@ VertexList[g];
    Subgraph[g, VertexList[g], GraphStyle -> "SimpleLink",
     VertexCoordinates -> coords]
    )
   ];


Another thing I was missing was a way to arrange the graph in a
topological sort up-down order like LayeredGraphPlot. LayeredDrawing
does not always do this. Luckily, you can do LayeredGraphPlot and take
it's vertex coordinates into Graph like below. Recipe below takes list
of edges and creates a Graph that looks like LayeredGraphPlot

(* extracts list of coordinates from VertexLabeled GraphPlot *)
getLabelCoordinateMap[gp1_] :=
  Module[{points, labels, actualLabels, coordAliases, actualCoords},
   points =
    Cases[gp1, GraphicsComplex[points_, __] :> points, Infinity] //
     First;
   labels = Cases[gp1, Text[___], Infinity];
   actualLabels = labels[[All, 1, 1]];
   coordAliases = labels[[All, 2]];
   actualCoords = points[[coordAliases]];
   Thread[actualLabels -> actualCoords]];

(* gets node coordinates, takes edges as list of Rule's *)
getLayeredGraphCoords[edges_] := Module[{gg, vcoordmap, vlist},
  gg = LayeredGraphPlot[edges, VertexLabeling -> True];
  vcoordmap = getLabelCoordinateMap[gg];
  vlist = VertexList[Graph[edges]];
  vlist /. vcoordmap
  ]

Graph[edges,VertexCoordinates -> getLayeredGraphCoords[streeStr]]





On Dec 2, 2:39 am, dr DanW <dmaxwar... at gmail.com> wrote:
> There are lots and lots of styling options in the new Graph function.
> Search on Graph in the Doc Center.  Use SetOptions to use set
> different default options.
>
> One thing which may be confusing you is that Graph is now the third
> implementation of graphing in Mathematica.  The first was in an older
> add on Combinatorica` (which itself went through two major revisions
> as I recall), than the built-in function GraphPlot, and now the first-
> class object Graph.  All of these are still in Doc Center, and you
> have to read carefully to see which is which.  They do not function
> identically.
>
> Wolfram developers: It would be very useful for us to have a tutorial
> that compares and contrasts these three very similar capabilities.
>
> Daniel




  • Prev by Date: Re: What function to use to find matrix condition number?
  • Next by Date: Re: [Please Help] How to get coefficient list from a
  • Previous by thread: Re: Changing Graph style
  • Next by thread: Re: Changing Graph style