Skip to main content
added 484 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
labels = Table[i -> Style[Subscript[v, i], 20], {i, 3}]
names = Table[i -> "longname_" <> "v_" <> ToString@i, {i, 3}];
colors = {1 -> Blue, 2 -> Red, 3 -> Green};  

legend = SwatchLegend[Last /@ colors, 
      Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
      LegendMarkers -> "Bubble"];

You can use Legended or, Epilog or Row to add legends to a Graph:

Legended[ Graph[Legended[Graph[{1 <-> 2, 2 <-> 3,  3 <-> 1},
  VertexStyle -> colors, VertexSize -> 0.1, 
  VertexLabels -> labels, ImagePadding -> 20],
 SwatchLegend[Last /@ colors, 
   Row[{#[[1]], ": ", #[[2]]}] &VertexStyle /@-> Transpose[{labelscolors, names}][[All,VertexLabels All-> labels, ImagePadding -1]]> 20], 
  LegendMarkers -> "Bubble"]]     legend]

enter image description here

Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1},
    VertexStyle -> colors, VertexSize -> 0.1, VertexLabels -> labels, 
    ImagePadding -> 5020, 
 Epilog -> Inset[SwatchLegend[Last /@Inset[legend, colors{.75, .75}]]
    

enter image description here

Row[{#[[1]],Graph[{1 ":<-> "2, #[[2]]}] &2 /@<-> Transpose[{labels3, names3 <-> 1}][[All, AllVertexStyle -> colors, VertexSize -1]]> 0.1, 
    LegendMarkers        VertexLabels -> "Bubble"]labels, {.75ImagePadding -> 20, .75ImageSize -> 300], 
    legend}]]]

enter image description hereenter image description here

labels = Table[i -> Style[Subscript[v, i], 20], {i, 3}]
names = Table[i -> "longname_" <> "v_" <> ToString@i, {i, 3}];
colors = {1 -> Blue, 2 -> Red, 3 -> Green}; 

You can use Legended or Epilog to add legends to a Graph:

Legended[ Graph[{1 <-> 2, 2 <-> 3,  3 <-> 1},
  VertexStyle -> colors, VertexSize -> 0.1, 
  VertexLabels -> labels, ImagePadding -> 20],
 SwatchLegend[Last /@ colors, 
   Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
  LegendMarkers -> "Bubble"]]

enter image description here

Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1},
    VertexStyle -> colors, VertexSize -> 0.1, VertexLabels -> labels, 
    ImagePadding -> 50, 
 Epilog -> Inset[SwatchLegend[Last /@ colors, 
    Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
    LegendMarkers -> "Bubble"], {.75, .75}]]

enter image description here

labels = Table[i -> Style[Subscript[v, i], 20], {i, 3}]
names = Table[i -> "longname_" <> "v_" <> ToString@i, {i, 3}];
colors = {1 -> Blue, 2 -> Red, 3 -> Green};  

legend = SwatchLegend[Last /@ colors, 
      Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
      LegendMarkers -> "Bubble"];

You can use Legended, Epilog or Row to add legends to a Graph:

Legended[Graph[{1 <-> 2, 2 <-> 3,  3 <-> 1},  VertexSize -> 0.1,
                VertexStyle -> colors, VertexLabels -> labels, ImagePadding -> 20], 
         legend]

enter image description here

Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1},
    VertexStyle -> colors, VertexSize -> 0.1, VertexLabels -> labels, 
    ImagePadding -> 20, 
 Epilog -> Inset[legend, {.75, .75}]]

enter image description here

Row[{Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1}, VertexStyle -> colors, VertexSize -> 0.1, 
            VertexLabels -> labels, ImagePadding -> 20, ImageSize -> 300], 
    legend}]

enter image description here

added 484 characters in body
Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929
labels = Table[i -> Style[Subscript[v, i], 20], {i, 3}]
names = Table[i -> "longname_" <> "v_" <> ToString@i, {i, 3}];
colors = {1 -> Blue, 2 -> Red, 3 -> Green}; 
 

You can use Legended or Epilog to add legends to a Graph:

Legended[ Graph[{1 <-> 2, 2 <-> 3,  3 <-> 1},
  VertexStyle -> colors, VertexSize -> 0.1, 
  VertexLabels -> labels, ImagePadding -> 20],
 SwatchLegend[Last /@ colors, 
  Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
  LegendMarkers -> "Bubble"]]

enter image description here

Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1},
    VertexStyle -> colors, VertexSize -> 0.1, VertexLabels -> labels, 
    ImagePadding -> 50, 
 Epilog -> Inset[SwatchLegend[Last /@ colors, 
    Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
    LegendMarkers -> "Bubble"], {.75, .75}]]

enter image description here

labels = Table[i -> Style[Subscript[v, i], 20], {i, 3}]
names = Table[i -> "longname_" <> "v_" <> ToString@i, {i, 3}];
colors = {1 -> Blue, 2 -> Red, 3 -> Green}; 
 
Legended[ Graph[{1 <-> 2, 2 <-> 3,  3 <-> 1},
  VertexStyle -> colors, VertexSize -> 0.1, 
  VertexLabels -> labels, ImagePadding -> 20],
 SwatchLegend[Last /@ colors, 
  Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
  LegendMarkers -> "Bubble"]]

enter image description here

labels = Table[i -> Style[Subscript[v, i], 20], {i, 3}]
names = Table[i -> "longname_" <> "v_" <> ToString@i, {i, 3}];
colors = {1 -> Blue, 2 -> Red, 3 -> Green}; 

You can use Legended or Epilog to add legends to a Graph:

Legended[ Graph[{1 <-> 2, 2 <-> 3,  3 <-> 1},
  VertexStyle -> colors, VertexSize -> 0.1, 
  VertexLabels -> labels, ImagePadding -> 20],
 SwatchLegend[Last /@ colors, 
  Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
  LegendMarkers -> "Bubble"]]

enter image description here

Graph[{1 <-> 2, 2 <-> 3, 3 <-> 1},
    VertexStyle -> colors, VertexSize -> 0.1, VertexLabels -> labels, 
    ImagePadding -> 50, 
 Epilog -> Inset[SwatchLegend[Last /@ colors, 
    Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
    LegendMarkers -> "Bubble"], {.75, .75}]]

enter image description here

Source Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

labels = Table[i -> Style[Subscript[v, i], 20], {i, 3}]
names = Table[i -> "longname_" <> "v_" <> ToString@i, {i, 3}];
colors = {1 -> Blue, 2 -> Red, 3 -> Green}; 

Legended[ Graph[{1 <-> 2, 2 <-> 3,  3 <-> 1},
  VertexStyle -> colors, VertexSize -> 0.1, 
  VertexLabels -> labels, ImagePadding -> 20],
 SwatchLegend[Last /@ colors, 
  Row[{#[[1]], ": ", #[[2]]}] & /@ Transpose[{labels, names}][[All, All, -1]],
  LegendMarkers -> "Bubble"]]

enter image description here