2
$\begingroup$

I'd like to ultimately have 3 inset boxes for information of 3 different lines on my graph. In order to minimalise the example I've just attempted 2 here, but the result is the same, that only the first box (in the top right) appears. Could anyone help me with this and identify what needs changing?

Code:

  Show[Plot[fit[x], {x, 0, 800}, PlotRange -> All, 
  PlotTheme -> "Detailed", PlotStyle -> Red, Axes -> False, 
  Frame -> {{True, False}, {True, False}}, 
  FrameLabel -> {"Time /s", 
    "Counts Recorded in the Previous 15 seconds"}, 
  ImageSize -> Large], 
 Plot[fit2[x], {x, 0, 800}, PlotRange -> All, PlotTheme -> "Detailed",
   PlotStyle -> Green, Axes -> False, ImageSize -> Large], 
 Plot[fit3[x], {x, 0, 800}, PlotRange -> All, PlotTheme -> "Detailed",
   PlotStyle -> Purple, Axes -> False, ImageSize -> Large], 
 ListPlot[dataHist5, ImageSize -> Large],
 Graphics[
  Inset[Framed[
    Column[{Style["Run 0", Bold], 
      Row[{"Text1"}], 
      Row[{"Text2"}], 
      Row[{"Text3"}], 
      Row[{"Text4"}], 
      Row[{"Text5"}]}], 
    Background -> White, RoundingRadius -> 5], {Right, Top}, 
   Scaled[{1.1, 1.2}]], 
  Inset[Framed[
    Column[{Style["Run 1", Bold], 
      Row[{"Text6"}], 
      Row[{"Text7"}], 
      Row[{"Text8"}], 
      Row[{"Text9"}], 
      Row[{"Text10"}]}], 
    Background -> White, RoundingRadius -> 5], {Left, Top}, 
   Scaled[{1.1, 1.2}]]], 
 PlotLabel -> 
  Style["Effects of Uncertainty Weightings - Run 0", Bold, 
   Black]]      

Output: enter image description here

Bonus Question:

Does anyone know how to put a single element of the legend in an inset box? So it just shows a Red Line, followed by fit[x], for example on one of the rows?

$\endgroup$
5
  • $\begingroup$ Have you tried using Epilog. $\endgroup$ Mar 11, 2021 at 17:00
  • $\begingroup$ No, I'm not so well versed in mathematica. That graph alone is well over a week's work in the making for me. Would you mind showing me how Epilog could reproduce a similar result? $\endgroup$
    – Epideme
    Mar 11, 2021 at 17:03
  • $\begingroup$ Can you explain the "Bonus Question" in more detail? Not sure what you mean by "on one of the rows"? $\endgroup$ Mar 11, 2021 at 19:14
  • $\begingroup$ Just put Insets in Graphics in braces: Graphics[{Inset[...],Inset[...]}] and adjust the position of the second inset? $\endgroup$
    – kglr
    Mar 11, 2021 at 20:44
  • $\begingroup$ @RohitNamjoshi Essentially, in the textbox insets - I'd quite like it that in one of the rows, which currently reads 'text 6' for example, it was one one element of the legend, say a red line, with fit (x) next to it, as appears next to the plot when the code is run $\endgroup$
    – Epideme
    Mar 12, 2021 at 9:15

2 Answers 2

2
$\begingroup$

When positioning multiple insets, I have found it useful to use the plot's coordinate system to indicate where in the plot I want some corner of the text box to be placed. I indicate the corner with Scaled. To demonstrate this technique, I will use the data and fit from a previous question of yours.

dataHist5 =
  {{Around[16.5, 1.5], Around[77.8, 8.8]}, 
   {Around[34.5, 1.5], Around[60.5, 8.0]},
   {Around[52.5, 1.5], Around[63.8, 8.0]}, 
   {Around[106.5, 1.5], Around[42.4, 6.5]},
   {Around[124.5, 1.5], Around[41.7, 6.5]}, 
   {Around[142.5, 1.5], Around[14.6, 3.8]},
   {Around[160.5, 1.5], Around[33.9, 5.8]}, 
   {Around[178.5, 1.5], Around[29.4, 5.4]},
   {Around[196.5, 1.5], Around[33.5, 5.8]}, 
   {Around[214.5, 1.5], Around[30.9, 5.6]},
   {Around[232.5, 1.5], Around[31.1, 5.8]}, 
   {Around[250.5, 1.5], Around[21.5, 4.6]},
   {Around[268.5, 1.5], Around[4.3, 2.1]}, 
   {Around[286.5, 1.5], Around[6.4, 2.5]},
   {Around[322.5, 1.5], Around[7.5, 2.7]}, 
   {Around[340.5, 1.5], Around[4.5, 2.1]},
   {Around[358.5, 1.5], Around[11., 3.3]}, 
   {Around[376.5, 1.5], Around[14.0, 3.7]},
   {Around[394.5, 1.5], Around[14.0, 3.7]}, 
   {Around[466.5, 1.5], Around[0.6, 0.7]},
   {Around[502.5, 1.5], Around[2.2, 1.5]}, 
   {Around[520.5, 1.5], Around[9.4, 3.1]},
   {Around[538.5, 1.5], Around[4.1, 2.0]}, 
   {Around[646.5, 1.5], Around[2.2, 1.5]},
   {Around[682.5, 1.5], Around[0.6, 0.7]}};
fitData = {#[[1, 1]], #[[2, 1]]} & /@ dataHist5;

Clear[A, k]
uncertainties = dataHist5[[All, 2, 2]];
fit =
  NonlinearModelFit[fitData, A Exp[-k t], {A, k}, t, Weights -> 1/uncertainties^2]

{A, k} = {A, k} /. fit["BestFitParameters"];
{σA, σk} = fit["ParameterErrors"];
hLife = Log[2]/Around[k, σk];
seA = Around[A, σA];
halfLife = hLife[[1]];
sehalfLife = hLife[[2]];

Show[
  Plot[fit[x], {x, 0, 800},
    PlotRange -> All,
    PlotTheme -> "Detailed",
    PlotStyle -> Red,
    Axes -> False,
    Frame -> {{True, False}, {True, False}}, 
    FrameLabel -> {"Time /s", "Counts Recorded in the Previous 15 seconds"},
    ImageSize -> Large],
  ListPlot[dataHist5, ImageSize -> Large],
  Graphics[
    {Inset[
       Framed[
         Column[
           {Style["Run 0", Bold],
            Row[{"Text1"}],
            Row[{"Text2"}],
            Row[{"Text3"}],
            Row[{"Text4"}],
            Row[{"Text5"}]}],
         Background -> White,
         RoundingRadius -> 5],
       {800, 30},
       Scaled[{1, 1}]],
     Inset[
       Framed[
         Column[
           {Style["Run 0", Bold],
            Row[{"Text1"}],
            Row[{"Text2"}],
            Row[{"Text3"}],
            Row[{"Text4"}],
            Row[{"Text5"}]}],
         Background -> White,
         RoundingRadius -> 5],
       {800, 58},
       Scaled[{1, 1}]],
     Inset[
       Framed[
         Column[
           {Style["Run 0", Bold],
            Row[{"N=" , Length[dataHist5], "/50"}],
            Row[{"A=" , seA}],
            Row[{Subscript[t, 1/2], "=", PlusMinus[halfLife, sehalfLife]}], 
            Row[{"χ^{2}=" , fit["ANOVATableSumsOfSquares"][[2]]}], 
            Row[{"Reduced χ^{2}=", fit["ANOVATableMeanSquares"][[2]]}]}],
         Background -> White,
         RoundingRadius -> 5],
       {800, 90},
       Scaled[{1, 1}]]}],
  PlotLabel -> 
    Row[{"Decay Curve of Phosphorus-31 by ", Superscript[β, "+"], " Emission"}]]

plot

This technique is advantageous when you want to line up the text boxes with one edge of the plot, which is often the case.

$\endgroup$
2
$\begingroup$

Using Epilog

epilog = {
   Inset[Framed[
     Column[{Style["Run 0", Bold], Row[{"Text1"}], 
       Row[{"Text2"}], Row[{"Text3"}], Row[{"Text4"}], 
       Row[{"Text5"}]}], Background -> White, RoundingRadius -> 5], 
    Scaled[{0, 1}], ImageScaled[{0, 1}]], 
   Inset[Framed[
     Column[{Style["Run 1", Bold], Row[{"Text6"}], Row[{"Text7"}], 
       Row[{"Text8"}], Row[{"Text9"}], Row[{"Text10"}]}], 
     Background -> White, RoundingRadius -> 5], Scaled[{1, 1}], 
    ImageScaled[{1, 1}]]};

Plot[Sin[x], {x, 0, 2 Pi}, Frame -> True, Epilog -> epilog]

enter image description here

$\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.