TransWikia.com

Placing labels at points using Show[plot, Graphics[...]]

Mathematica Asked on February 16, 2021

How do I label a point that I add to a plot of some kind using Show[plot,Graphics[...]], from the documentation I cannot find out the correct way. I would have thought that the following would work but it produces an error:

Show[RegionPlot[x > y, {x, -2, 2}, {y, -2, 2}],
 Labeled[Graphics[{Red, Point[{1/6, 1/3}]}] , "a"]
 ]

(See also this closed question: Placing a label at a point, which was judged off-topic even though it looks completely on-topic too me.)

One Answer

It does not work because Labeled is not a Graphics primitive or directive. Some alternatives

Using the Text primitive and Show

Show[
 RegionPlot[x > y, {x, -2, 2}, {y, -2, 2}],
 Graphics[{Red, Point[{1/6, 1/3}], Black, Text["a", {1/6 - .1, 1/3}]}]]

enter image description here

Using Epilog

RegionPlot[x > y, {x, -2, 2}, {y, -2, 2},
 Epilog -> {Red, Point[{1/6, 1/3}], Black, Text["a", {1/6 - .1, 1/3}]}]

The result is the same as using Show.

Using ListPlot, Callout and Show

Show[RegionPlot[x > y, {x, -2, 2}, {y, -2, 2}], 
 ListPlot[Callout[{{1/6, 1/3}}, "a", Left], Axes -> False, PlotStyle -> Red]]

enter image description here

With Callout there are many options for customizing the appearance.

Answered by Rohit Namjoshi on February 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP