MathGroup Archive 2008

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

Search the Archive

Re: Re: changing style of vertices for ShowGraph

  • To: mathgroup at smc.vnet.net
  • Subject: [mg87114] Re: [mg86376] Re: [mg86332] changing style of vertices for ShowGraph
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Tue, 1 Apr 2008 03:21:51 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200803070729.CAA19892@smc.vnet.net> <C63D1D41-0058-431D-A84D-4418E66DBF46@lse.ac.uk> <200803081044.FAA13587@smc.vnet.net> <200803091007.FAA15620@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

But I want to reproduce with GraphPlot some of the old behavior of 
DiscreteMath`Combinatorica`ShowGraph (since some other of its behavior 
seems to have disappeared in Mathematica 6).  Namely, to show the vertex 
labels not AT the vertices but rather near the vertices, so that I can 
still use solid disks for the vertices.

If I do something like this...

   GraphPlot[Cycle[3],Method->Automatic,
     VertexLabeling->True,
     VertexRenderingFunction->({Black,Disk[#1,0.02],Black,Text[#2,#1]}&)]

... then I get the disks but no labels, because evidently one of the 
arguments of Text[#2,#1] -- which one?? (this doesn't seem to be 
documented?) -- is giving the location to be AT the vertices.

With some experimentation, I discover that it's argument #1 that gives 
the coordinates of the vertex, so I can use something like:

   GraphPlot[Cycle[3],Method->Automatic,
     VertexLabeling->True,
     VertexRenderingFunction->
       ({Black,Disk[#1,0.02],Black,Text[#2,#1+{0.05,0.05}]}&)]

But this is SO much work for something that was SO simple with ShowGraph!


J. McKenzie Alexander wrote:
> Setting the option VertexLabeling->True has no effect when a custom  
> definition is provided for VertexRenderingFunction, as VertexLabeling  
> only affects how the default rendering function draws the vertices.   
> If you want vertex labels provided you need to include that in the  
> definition of the custom rendering function.
> 
> Look up the documentation for VertexRenderingFunction and  
> EdgeRenderingFunction to see what additional arguments are provided.  
> The first argument for VertexRenderingFunction is the position of the  
> vertex. The second argument is the label.  So the following works:
> 
> GraphPlot[Cycle[3], Method -> Automatic, VertexLabeling -> True,
>   EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]} &),
>   VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}],  
> Yellow,
>       Disk[#1, 0.04], Black, Text[#2, #1]} &)]
> 
> You can drop the option settings for VertexLabeling and EdgeLabeling  
> and get the same effect.
> 
> As for whether GraphPlot plays well with the Combinatorica graph  
> structure, it does handle vertex labels correctly but not edge labels,  
> as the following example illustrates.  I was personally surprised to  
> find that the edge labels were not passed to EdgeRenderingFunction.  I  
> think this might be a bug.
> 
> GraphPlot[
>   Graph[{{{1, 2}, EdgeLabel -> "e1"}, {{2, 3}, EdgeLabel -> "e2"},  
> {{3, 1},
>      EdgeLabel -> "e3"}},
>    {{{-0.5, 0.866}, VertexLabel -> "a"},
>     {{-0.5, -0.866}, VertexLabel -> "b"},
>     {{1., 0}, VertexLabel -> "c"}}],
>   EdgeRenderingFunction -> ({Black, Line[#1],
>       Text[#3, Mean[#1]]
>       } &),
>   VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}],  
> Yellow,
>       Disk[#1, 0.04], Black, Text[#2, #1]} &)]
> 
> Cheers,
> 
> Jason
> 
> On 8 Mar 2008, at 10:44, Murray Eisenberg wrote:
> 
>> Yes, GraphPlot seems to permit making nice vertices (or edges), but  
>> then
>> the labeling -- either with a Graph object from Combinatorica or just
>> the kind of graph described by the GraphPlot reference page -- does  
>> not
>> seem to admit vertex labels or edge labels, at least so far as I can
>> see.  For example, neither of the following displays either vertex
>> labels or edge labels:
>>
>>
>> GraphPlot[Cycle[3], Method -> Automatic, VertexLabeling -> True,
>>  EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]} &),
>>   VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}],
>>      Yellow, Disk[#1, 0.04]} &)]
>>
>> GraphPlot[{{v1 -> v2, "a"}, {v2 -> v3, "b"}, {v3 -> v1, "c"}},
>>  Method -> Automatic, VertexLabeling -> True, EdgeLabeling -> True,
>>  EdgeRenderingFunction -> ({Black, Line[#1]} &),
>>  VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}],
>>      Yellow, Disk[#1, 0.04]} &)]
>>
>> On the other hand, if I remove he VertexRenderingFunction option, I do
>> see vertex labels on the default (yellow boxes) vertex shapes:
>>
>>  GraphPlot[{v1 -> v2, "a"}, {v2 -> v3, "b"}, {v3 -> v1, "c"}},
>>   Method -> Automatic, VertexLabeling -> True,
>>    EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]}  
>> &)]
>>
>> GraphPlot[Cycle[3], Method -> Automatic, VertexLabeling -> True,
>>  EdgeLabeling -> True, EdgeRenderingFunction -> ({Black, Line[#1]} &)]
>>
>> Of course this now defeats the purpose of using GraphPlot so as to get
>> exactly the kind of vertex shapes that VertexRenderingFunction, above,
>> provides.
>>
>> Similarly with EdgeRenderingFunction.
>>
>> The kernel function GraphPlot doesn't seem to mesh very well with
>> Combinatorica's graph functions.  This all still seems only "half- 
>> baked".
>>
>>
>> J. McKenzie Alexander wrote:
>>> Take a look at GraphPlot, the graph rendering function that is built
>>> into the Mathematica kernel.  I switched from using ShowGraph to
>>> GraphPlot after realising that it was (a) faster and (b) easier to
>>> customise.  Here's what you want:
>>>
>>> GraphPlot[
>>> Cycle[3],
>>> Method -> None,
>>> EdgeRenderingFunction -> ({Black, Line[#1]} &),
>>> VertexRenderingFunction -> ({EdgeForm[{Thickness[0.005], Red}],  
>>> Yellow,
>>>     Disk[#1, 0.04]} &)
>>> ]
>>>
>>> You need to specify Method->None, otherwise GraphPlot will override  
>>> the
>>> specified positions of the vertices in the graph and use its own  
>>> default
>>> vertex positioning algorithm.
>>>
>>> VertexRenderingFunction is what you need to define in order to  
>>> customise
>>> the appearance of the vertices.
>>>
>>> I provided a definition of EdgeRenderingFunction just so that the  
>>> edges
>>> are rendered in the same way as ShowGraph.
>>>
>>> Cheers,
>>>
>>> Jason
>>>
>>> -- 
>>> J. McKenzie Alexander
>>> Department of Philosophy, Logic and Scientific Method
>>> London School of Economics and Political Science
>>> Houghton Street, London WC2A 2AE
>>>
>>>
>>> On 7 Mar 2008, at 07:29, Murray Eisenberg 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]]
>>>>
>>>> -- 
>>>> 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
>>>>
>>>
>>>
>>>
>>>
>>>
>>> Please access the attached hyperlink for an important electronic
>>> communications disclaimer:
>>> http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
>>>
>> -- 
>> 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
>>
> 
> --
> Dr J. McKenzie Alexander
> Department of Philosophy, Logic and Scientific Method
> London School of Economics and Political Science
> Houghton Street, London WC2A 2AE
> 
> 
> 
> 
> Please access the attached hyperlink for an important electronic communications disclaimer: http://www.lse.ac.uk/collections/secretariat/legal/disclaimer.htm
> 

-- 
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


  • Prev by Date: Re: Problems with differentiating Piecewise functions
  • Next by Date: Re: Mathematica notebooks the best method for technical
  • Previous by thread: Re: Problems with differentiating Piecewise functions
  • Next by thread: Re: Mathematica notebooks the best method for technical