MathGroup Archive 2009

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

Search the Archive

Re: Re: Re: Using GraphPlot to draw

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105446] Re: [mg105435] Re: [mg105381] Re: [mg105358] Using GraphPlot to draw
  • From: Murray Eisenberg <murray at math.umass.edu>
  • Date: Thu, 3 Dec 2009 06:13:34 -0500 (EST)
  • Organization: Mathematics & Statistics, Univ. of Mass./Amherst
  • References: <200911291011.FAA16287@smc.vnet.net> <200911301111.GAA13302@smc.vnet.net> <200912021127.GAA26780@smc.vnet.net>
  • Reply-to: murray at math.umass.edu

The following method is as suggested in this group by Carl Woll in 
rsponse to a posting of mine on the same subject of labeling edges.

m = {{0, 1, 1}, {1, 0, 1}, {1, 1, 0}};
labels = {0.5, 0.5, 0.5, 0.5, 0.5, 0.5};
edgeLabelFunction[{u_, v_}] :=
  labels[[First@Flatten@Position[Edges[g], {u, v} | {v, u}]]]

GraphPlot[m, DirectedEdges -> True,
  EdgeRenderingFunction -> ({
      Arrowheads[{{0.5, 0.5,
         Graphics[{
           Blue,

           Inset[Style[edgeLabelFunction[#2]], {0, 0},
            ImageScaled[{0.5, 0.5}], Automatic, None,
            Background -> White]
           }]}}], Arrow[#1]} &), BaseStyle -> 16]

This seems a horrible way to have to do it. Clearly the introduction of 
of GraphPlot in place of Combinatorica`ShowGraph was either misconceived 
or is as yet only half-baked. Otherwise, there is no good reason that 
such an obviously simple thing as labeling edges should be so difficult.


J. McKenzie Alexander wrote:
> Many thanks to all those who responded. One further question: how does one assign labels to edges if calling GraphPlot on an adjacency matrix? I tried the following (which struck me as a natural guess at what the syntax might be), but it failed:
> 
> GraphPlot[
> { {0, {1, 0.5}, {1, 0.5}},
> { {1, 0.5}, 0, {1, 0.5}},
> { {1, 0.5}, {1, 0.5}, 0}}, MultiedgeStyle -> True]
> 
>>From what I see in the documentation, there doesn't seem to be a way to include edge labels using the adjacency matrix representation, unless I explicitly override EdgeRenderingFunction. Is that right?
> 
> Cheers,
> 
> Jason
> 
> 
> On 30 Nov 2009, at 11:11, Murray Eisenberg wrote:
> 
>> You can finesse this by using the form
>>
>>   GraphPlot[m]
>>
>> where m is the adjacency matrix.  For example, for a 3-vertex null graph:
>>
>>   GraphPlot[ConstantArray[0, {3, 3}]]
>>
>>
>> J. McKenzie Alexander wrote:
>>> Hello,
>>>
>>> Is there a way of making GraphPlot draw an empty graph? I realise that
>>> this is an ill-defined question if one uses the default options for
>>> GraphPlot because there is no way for GraphPlot to know how many
>>> vertices it should draw. However, it turns out that even if one set a
>>> custom value for VertexCoordinateRule the vertices aren't drawn:
>>>
>>> GraphPlot[{},
>>> VertexRenderingFunction -> ({Black, Disk[#1, 0.05] } &),
>>> VertexCoordinateRules ->
>>> Table[{Cos[theta], Sin[theta]}, {theta, 0, 2 Pi, 2 Pi/11}]
>>> ]
>>>
>>> I know that I could easily draw this "by hand" using Graphics, but I
>>> have good reason for wanting to use GraphPlot. (I wrap the GraphPlot in
>>> Dynamic where the list of edges is specified by a variable. Most of the
>>> time the variable contains a connected graph, but sometimes it is
>>> empty.)
>>>
>>> As an aside, the following "works" as a way of giving the impression of
>>> an empty graph, but it does so by forcing each node to have a self-loop
>>> (and then suppressing those edges from being drawn). It would be nice to
>>> have a cleaner solution.
>>>
>>> GraphPlot[Table[i -> i, {i, 0, 11}],
>>> VertexRenderingFunction -> ({Black, Disk[#1, 0.05]} &),
>>> SelfLoopStyle -> None,
>>> VertexCoordinateRules ->
>>> Table[N[{Cos[theta], Sin[theta]}], {theta, 0, 2 Pi, 2 Pi/11}]
>>> ]
>>>
>>> Cheers,
>>>
>>> Jason
>>>
>>> --
>>> Dr J. McKenzie Alexander
>>> Department of Philosophy, Logic and Scientific Method
>>> London School of Economics and Political Science
>>> Houghton Street, London WC2A 2AE
>>>
>>>
>>>
>>>
>> --
>> 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: Re: Permanent Computation Efficiency
  • Next by Date: Re: How to make large graphics object fit within a plot?
  • Previous by thread: Re: Re: Using GraphPlot to draw an empty graph
  • Next by thread: How to make large graphics object fit within a plot?