4

In an attempt to create a legend for a graph drawing, I find that Labeled only works without the position options (except for Center).

   Graph[Range[2], {
  Labeled[DirectedEdge[1, 2], "BEFORE"]}]

enter image description here

But

Graph[Range[2], {
  Labeled[DirectedEdge[1, 2], "BEFORE", Bottom]}]

enter image description here

Similarly for the other Labeled position options like Top, Left, Right.

Also, adding ImagePadding doens't help. I've tried some - but not all - Labeled's other options:

{Alignment -> {Center, Baseline}, Background -> None, 
 BaselinePosition -> Automatic, BaseStyle -> {}, 
 DefaultBaseStyle -> "Labeled", DefaultLabelStyle -> "LabeledLabel", 
 Editable -> Automatic, Frame -> None, FrameMargins -> 0, 
 FrameStyle -> Automatic, ImageMargins -> 0, ImageSize -> Automatic, 
 LabelStyle -> {}, RotateLabel -> False, RoundingRadius -> 0, 
 Selectable -> Automatic, Spacings -> Automatic, 
 SyntaxForm -> Automatic}

Known issue?

alancalvitti
  • 15,143
  • 3
  • 27
  • 92
  • I think that with Bottom the label falls below the plot area and thus does not show... try setting the option PlotRange to show a larger vertical area. – a06e May 11 '13 at 03:32

1 Answers1

5

I do not see any advantage of using Labeled vs intended for graphs EdgeLabels. Here is an aap to demonstrate arbitrary label placement:

Manipulate[Graph[{1 \[DirectedEdge] 2}, EdgeLabels -> {1 \[DirectedEdge] 2 -> 
  Placed[Style["OVERLAP", Red, 15], {a, p}]}, 
  PlotRange -> {{-.5, 1.5}, {-.15, .15}}, EdgeShapeFunction -> esf],
  {{esf, "Arrow", "Arrowheads"}, {"Line", "Arrow"}},
  {{p, {.5, .7}, "scaled position\nin the label"}, {-2, 0}, {3, 1.5}}, 
  {{a, .5, "scaled position of\nthe label along edge"}, 0, 1}]

enter image description here

Vitaliy Kaurov
  • 73,078
  • 9
  • 204
  • 355
  • 2
    that's an option but my intention is to build legends for graphs, using Row, Column, Grid. In any case, something is broken in Labeled-Graph interaction. – alancalvitti Sep 07 '12 at 20:37
  • @alancalvitti Can you show how you intend to use Row, etc. for this? – Vitaliy Kaurov Sep 07 '12 at 20:48
  • for example: Column[{ Column[{"OVERLAP", Graph[{Style[DirectedEdge[1, 2], Red]}, ImageSize -> 150]}, Center, -0.5], Column[{"BEFORE", Graph[{Style[DirectedEdge[1, 2], Blue]}, ImageSize -> 150]}, Center, -0.5], Column[{"AFTER", Graph[{Style[DirectedEdge[1, 2], Green]}, ImageSize -> 150]}, Center, -0.5] }] – alancalvitti Sep 07 '12 at 20:51
  • I suppose all this can be done within Graph by specifying vertex positions, but I prefer not specifying all these small details. – alancalvitti Sep 07 '12 at 20:52
  • By the way, this is a separate Q but shouldn't I be able to remove the arrowheads w/ Arrowheads? Ie, Graph[{Style[DirectedEdge[1, 2], Red, Arrowheads[0]] but that doesn't do it. – alancalvitti Sep 07 '12 at 20:56
  • @alancalvitti for removing arrowheads - why not to use just UndirectedEdge ? – Vitaliy Kaurov Sep 07 '12 at 21:03
  • @alancalvitti It is possible with EdgeShapeFunction. But generally for removing arrowheads - why not to use just UndirectedEdge ? – Vitaliy Kaurov Sep 07 '12 at 21:14
  • Nice! To round it into an awesome app, you could have an input field to enter the label and operate only on the selected edge. – rm -rf Sep 07 '12 at 21:59
  • Re arrowheads - because this problem (TimeML markup) results in hybrid Directed and UndirectedEdges, which Graph does not support, though there's code here but it's not transparent: http://mathematica.stackexchange.com/questions/6282/how-can-i-replace-bi-directional-directededge-pairs-in-a-graph-with-a-single-und – alancalvitti Sep 07 '12 at 22:00
  • @alancalvitti I added code showing how to control arrowheads ON/OFF . – Vitaliy Kaurov Sep 07 '12 at 22:10
  • @R.M Thanks! Yes, if I find some time ;) – Vitaliy Kaurov Sep 07 '12 at 22:11
  • Nice (+1). Graph[{Labeled[DirectedEdge[1, 2], Placed["label", {a, p}]]}] also works. – kglr Sep 07 '12 at 23:57
  • 1
    @VitaliyKaurov,+1 but cannot accept. The issue is the orthogonality of the language. Why don't all Labeled options work with Graph? – alancalvitti Sep 08 '12 at 18:08