0
$\begingroup$

Question:

I would like to have a second inset box on the graph below, as a legend for the graph but it's not showing. I tried to do make it work by editting an old example I had from another question, but it's still just printing the graph (correctly) but without the inset box (which should go underneath the box that can be seen)

Code:

    dataHist5 = {{15, 74}, {33, 64}, {51, 62}, {69, 54}, {87, 47}, {105, 
    39}, {123, 40}, {141, 35}, {159, 34}, {177, 29}, {195, 34}, {213, 
    30}, {231, 31}, {249, 22}, {267, 14}, {285, 14}, {303, 13}, {321, 
    25}, {339, 18}, {357, 11}, {375, 13}, {393, 16}, {411, 13}, {429, 
    12}, {447, 10}, {465, 12}, {483, 11}, {501, 13}, {519, 9}, {537, 
    8}, {555, 7}, {573, 5}, {591, 5}, {609, 4}, {627, 5}, {645, 
    2}, {663, 1}, {681, 3}, {699, 2}, {717, 2}, {735, 1}, {753, 
    1}, {771, 1}, {789, 0}, {807, 0}, {825, 1}, {843, 2}, {861, 
    0}, {879, 1}, {897, 1}};
(*Raw counts in fixed interval. No dead time on first point - +3s to \
all the x variables to include it again*)

glm = GeneralizedLinearModelFit[dataHist5, t, t, 
  ExponentialFamily -> "Poisson"]

ln2 = Log[E, 2]
halfLife = Abs[(ln2/glm["ParameterTableEntries"][[2, 1]])]
sehalfLife = 
 Abs[(((glm["ParameterTableEntries"][[2, 2]])/(glm[
         "ParameterTableEntries"][[2, 1]])))*halfLife*ln2]
(*sigmaT=Abs[t]*ln(2)*(sigmaK/K)*)
k = glm["ParameterTableEntries"][[2, 1]]
\[Sigma]k = glm["ParameterTableEntries"][[2, 2]]
edp = glm["DevianceTableEntries"][[2, 4]]
redp = (glm["DevianceTableEntries"][[2, 4]])/(glm[
     "DevianceTableEntries"][[2, 3]])
A = E^(glm["ParameterTableEntries"][[1, 1]])
\[Sigma]A = ( 
  A*(glm["ParameterTableEntries"][[1, 
      2]]))(*sigmaA=A*sigma(e^a). Where a is Y = e^(a)*e(-kt), and \
e^(a)=A*)

Show[Plot[glm[t], {t, 0, 900}, 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[A*Exp[-0.00462480948*x], {x, 0, 900}, PlotRange -> All, 
  PlotTheme -> "Detailed", PlotStyle -> Blue, Axes -> False, 
  ImageSize -> Large], ListPlot[dataHist5], 
 Graphics[{Inset[
    Framed[Column[{Style["Run 0", Bold], 
       Row[{"Data Points = ", Length[dataHist5], "/50"}], 
       Row[{Subscript[t, Style["1/2", FontSize -> 10]], " = ", 
         PlusMinus[NumberForm[halfLife, 4], 
          NumberForm[sehalfLife, 3]]}], 
       Row[{"A = " PlusMinus[Round[A], Round[\[Sigma]A]]}], 
       Row[{"\[Lambda] = " PlusMinus[NumberForm[k, 3], 
           NumberForm[\[Sigma]k, 2]]}], 
       Row[{"D = ", NumberForm[edp, 4]}], 
       Row[{"Reduced D = ", NumberForm[redp, 3]}]}], 
     Background -> White, RoundingRadius -> 5], {Right, Top}, 
    Scaled[{1.1, 1.2}]], 
   Inset[Framed[
     Column[{LineLegend[{Blue}, {Style[TraditionalForm@"Reference"]}],
        Row[{LineLegend[{Red}, {Style[
            TraditionalForm@"Experimental"]}]}]}], 
     Background -> White, RoundingRadius -> 5], {Right, 0.1}, 
    Scaled[{1.1, 1.2}]]}], 
 PlotLabel -> 
  Style["Decay Curve of Phosphorus-30 by \[Beta]+ Emission", Bold]]

Result:

enter image description here

Thoughts:

I think the problem might be to do with where my brackets are, but I can't see where or what bracket might be wrong or missing.

$\endgroup$
1
  • 1
    $\begingroup$ When posting, please reduce the example to the minimum required to demonstrate the issue and include all data and code required for the minimal example to execute. $\endgroup$
    – Bob Hanlon
    May 7, 2021 at 16:47

1 Answer 1

3
$\begingroup$

Changed some brackets inside the second Inset:

Show[Plot[glm[t], {t, 0, 900}, 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[A*Exp[-0.00462480948*x], {x, 0, 900}, PlotRange -> All, 
  PlotTheme -> "Detailed", PlotStyle -> Blue, Axes -> False, 
  ImageSize -> Large], ListPlot[dataHist5], 
 Graphics[{Inset[
    Framed[Column[{Style["Run 0", Bold], 
       Row[{"Data Points = ", Length[dataHist5], "/50"}], 
       Row[{Subscript[t, Style["1/2", FontSize -> 10]], " = ", 
         PlusMinus[NumberForm[halfLife, 4], 
          NumberForm[sehalfLife, 3]]}], 
       Row[{"A = " PlusMinus[Round[A], Round[\[Sigma]A]]}], 
       Row[{"\[Lambda] = " PlusMinus[NumberForm[k, 3], 
           NumberForm[\[Sigma]k, 2]]}], 
       Row[{Superscript[D, 2], "= ", NumberForm[edp, 4]}], 
       Row[{"Reduced " Superscript[D, 2], "= ", 
         NumberForm[redp, 3]}]}], Background -> White, 
     RoundingRadius -> 5], {Right, Top}, Scaled[{1.1, 1.2}]], 
   Inset[Framed[Column[{
       LineLegend[{Blue}, {Style[TraditionalForm@"Reference"]}], 
       Row[{LineLegend[{Red}, {Style[
            TraditionalForm@"Experimental"]}]}]}], 
     Background -> White, RoundingRadius -> 5], {Right, 0.1}, 
    Scaled[{1.1, 1.2}]]}], 
 PlotLabel -> 
  Style["Decay Curve of Phosphorus-30 by \[Beta]+ Emission", Bold]]

and seems to work:

enter image description here

$\endgroup$
1
  • $\begingroup$ That's perfect, thank you! $\endgroup$
    – Epideme
    May 10, 2021 at 9:43

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.