2
$\begingroup$

I'd like to label a name $K_4$ in following graph. How to do that?

completegraph4 = ImportString["C~", "Graph6"]

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ Graph[completegraph4, PlotLabel -> Style["K_4", 16]]? $\endgroup$
    – kglr
    Apr 15 '20 at 9:00
  • $\begingroup$ ... or Labeled[completegraph4, Style["K_4", 16], Top]? $\endgroup$
    – kglr
    Apr 15 '20 at 9:01
  • $\begingroup$ Thanks! I'd like to ask more, How to adjust the position of label ? $\endgroup$
    – licheng
    Apr 15 '20 at 9:07
  • 1
    $\begingroup$ I'm wondering: Did the OP even look at the documentation for Graph which answers all this? $\endgroup$ Apr 15 '20 at 17:42
6
$\begingroup$

All Graphics options work in Graph. You can use PlotLabel or add a Text primitive to the Epilog.

label = Style["\!\(\*SubscriptBox[\(K\), \(4\)]\)", 16]

CompleteGraph[4, PlotLabel -> label]

CompleteGraph[4, Epilog -> Text[label, Scaled[{0.8, 0.8}]]]

You could also use Labeled.

$\endgroup$
4
$\begingroup$

If you want to place the label at the top you can use the option PlotLabel:

Graph[completegraph4, PlotLabel -> Style["K_4", 16]]

enter image description here

Or wrap the graph object with Labeled:

Labeled[completegraph4, Style["K_4", 16], Top]

enter image description here

Labeled[completegraph4, Style["K_4", 16], Right]

enter image description here

To get a finer control on label position you can use Legended + Placed:

Legended[completegraph4, Placed[Style["K_4", 16], {.8, .9}]]

enter image description here

You can also use Locator to place the label interactively:

DynamicModule[{loc = {.8, .8}}, 
 Dynamic @ Show[Graph[completegraph4], Graphics[{Locator[loc, Style["K_4", 16]]}]]]

enter image description here

or

DynamicModule[{loc = {.8, .8}}, 
 Graph[completegraph4, Epilog -> {Dynamic@Locator[loc, Style["K_4", 16]]}]]

enter image description here

$\endgroup$
1
  • $\begingroup$ haha, Magical mma! $\endgroup$
    – licheng
    Apr 15 '20 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.