4
$\begingroup$

I use this command

ListPlot[idata27, 
  Frame -> True, 
  PlotRange -> {All, All}, 
  Epilog -> 
    {Inset[
       Framed[Style["Here", 20], RoundingRadius -> 5, Background -> White], 
       {100, 19.6}]}]

to make this plot for a list of data

enter image description here

But I can't determine the x and y coordinates of the Epilog text to make it appear inside the plot. What should I do?

$\endgroup$

2 Answers 2

2
$\begingroup$

The position argument of inset is wrong. Try this

ListPlot[{#, #2/(# - 390)} & @@ # & /@ 
  Thread[{400 + 10 RandomInteger[10, 100], RandomReal[10, 100]}], 
Frame -> True, PlotRange -> {All, All}, Epilog -> {
  Inset[Framed[Style["Here", 20], RoundingRadius -> 5, Background -> White], {440, 1/2}]}]

enter image description here

$\endgroup$
5
$\begingroup$

Coolwater's answer works well, but there are also ways of placing an insert without having to use actual plot coordinates.

Here are some examples. I use Coolwater's data generator.

SeedRandom[42];
data = {#, #2/(# - 390)} & @@ # & /@ 
   Thread[{400 + 10 RandomInteger[10, 100], RandomReal[10, 100]}];

Scaled positions

When scaled positions are used, {0, 0} refers to the left, bottom corner of the graphics viewport and {1, 1} refers to the right, top corner; consequently, {1/2, 1/2} refers to the center. So to center the text horizontally and put it near the top of screen, we can write

ListPlot[data, 
  Frame -> True, PlotRange -> {All, All},
  Epilog -> 
    {Inset[
       Framed[Style["Here", 20], RoundingRadius -> 5, Background -> White], 
       Scaled[{1/2, 1 - 1/8}]]}]

plot1

Named positions

Named positions are accepted as a convenience but do not give fine control. Let's try to put the text in the top-right corner of the plot with named controls. The 3rd argument of Inset comes into play here; without it only the lower-left quadrant of the text box would be visible.

ListPlot[data, 
  Frame -> True, 
  PlotRange -> All,
  PlotRangeClipping -> False,
  Epilog ->
    {Inset[
       Framed[Style["Here", 20], RoundingRadius -> 5, Background -> White],
       {Right, Top}, 
       {Right, Top}]}]

plot2

This would look good if the plot weren't framed,

ListPlot[data,
  PlotRange -> All,
  PlotRangeClipping -> False,
  Epilog ->
    {Inset[
       Framed[Style["Here", 20], RoundingRadius -> 5],
       {Right, Top},
       {Right, Top}]}]

plot3

but it does't look good with a framed plot. For a framed plot, we need more control, which brings me to my next topic.

Mixing named and scaled positions

The problem we saw above can be fixed by using a scaled position to adjust the placement of the text. We nudges down and to the left in the plot by moving its reference point up and to right. Like so.

ListPlot[data,
  Frame -> True,
  PlotRange -> All,
  Epilog ->
   {Inset[
      Framed[Style["Here", 20], RoundingRadius -> 5, Background -> White],
      {Right, Top},
      Scaled[{9/8, 9/8}]]}]

plot4

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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