Re: Label vertices in Graph to display with GraphPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg87276] Re: [mg87213] Label vertices in Graph to display with GraphPlot
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Sun, 6 Apr 2008 06:43:35 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <200804040758.CAA03960@smc.vnet.net>
- Reply-to: murray at math.umass.edu
At last I figured it out. (And no thanks to the documentation.)
Here's a simple example of using non-default vertex labels in a
GraphPlot display with a graph created by a GraphPlot function:
<<Combinatorica`
labels = {"a", "b", "c", "d"};
GraphPlot[Wheel[4], Method -> None,
VertexRenderingFunction ->
({EdgeForm[{Brown}], Yellow, Disk[#1, 0.05],
Black, Text[labels[[#2]], #1]} &),
BaseStyle -> {FontSize -> 16}]
The "secret" is in the meaning of the slot argument #2 to Text within
the VertexRenderingFunction.
Murray Eisenberg wrote:
> I'm using some Combinatorica functions to create graphs where I do not
> specify individually the vertices -- and hence do not individually
> specify the vertex labels I want, e.g.:
>
> g = RotateVertices[Cycle[5], \[Pi]/10]; g = AddEdge[g, {2, 5}];
> g = SetGraphOptions[g, VertexLabel -> Characters["abcde"]];
>
> If I use Combinatorica`ShowGraph, then I'll see the vertex labels:
>
> ShowGraph[g]
>
> However, if I use Mathematica 6's kernel function GraphPlot, I don't see
> these individual labels, but rather the entire list {a,b,c,d,e} of
> labels at each vertex!
>
> GraphPlot[g,Method->None,VertexRenderingFunction->(Text[#2,#1]&)
>
> How do I coerce GraphPlot to reproduce the behavior of ShowGraph, so
> that it labels the individual vertices with a, b, c, d, e?
>
> (The interaction between Combintorica's graph-creating functions, on the
> one hand, and GraphPlot, on the other hand, remains mysterious and
> severely underdocumented for me.
>
> It seems there's a clear attempt to migrate display of graphs to the
> kernel function GraphPlot and thereby discourage use of ShowGraph, yet
> in almost everything I've attempted so far, GraphPlot does not so
> readily or gracefully reproduce the functionality of Combinatorica'a
> ShowGraph. This is most especially the case as it affects relative
> newcomers to Mathematica like my students.)
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
- Follow-Ups:
- Re: Re: Label vertices in Graph to display with GraphPlot
- From: "J. McKenzie Alexander" <jalex@lse.ac.uk>
- Re: Re: Label vertices in Graph to display with GraphPlot
- References:
- Label vertices in Graph to display with GraphPlot
- From: Murray Eisenberg <murray@math.umass.edu>
- Label vertices in Graph to display with GraphPlot