2
$\begingroup$

I have tried to plot the next FTIR spectrum and add their respective peak labels using Graphics and Show, but I think this doesn't work with ScalingFunctions, because the peak labels don't appear. Do you know any other way to do it?

ir = Import[
   "C:/Users/gafla/Documents/FQ Avanzada/dfrx_2.xlsx", {"Data", 1, 
    Range[2, 935], {8, 9}}];
ir1 = Rotate[
   Style[Text["1500.6 \[LongRightArrow]", {1500.618848, 95.9 - .3}], 
    12, Bold], 90 Degree];
ir2 = Rotate[
   Style[Text["1348.9 \[LongRightArrow]", {1348.889888, 96.4 - .3}], 
    12, Bold], 90 Degree];
ir3 = Rotate[
   Style[Text["1045.4 \[LongRightArrow]", {1045.418272, 97.0 - .3}], 
    12, Bold], 90 Degree];
ir4 = Rotate[
   Style[Text["956.7 \[LongRightArrow]", {956.692736, 96.3 - .3}], 12,
     Bold], 90 Degree];
ir5 = Rotate[
   Style[Text["833.2 \[LongRightArrow]", {833.248512, 96.0 - .3}], 12,
     Bold], 90 Degree];
ir6 = Rotate[
   Style[Text["705.9 \[LongRightArrow]", {705.946656, 96.6 - .3}], 12,
     Bold], 90 Degree];
ir7 = Rotate[
   Style[Text["459.0 \[LongRightArrow]", {459.058208, 96.4 - .3}], 12,
     Bold], 90 Degree];

txtir = Graphics[{ir1, ir2, ir3, ir4, ir5, ir6, ir7}];

pir = ListLinePlot[{ir}, ScalingFunctions -> {"Reverse", Automatic}, 
   Frame -> True, FrameStyle -> Directive[Black, 12], 
   FrameTicks -> {{None, None}, {Range[400, 4000, 400], None}}, 
   AspectRatio -> 1/2, 
   FrameLabel -> {{"Transmitancia (%)", 
      None}, {"Número de onda (\!\(\*SuperscriptBox[\(cm\), \
\(-1\)]\))", None}}, PlotStyle -> Red, 
   PlotRange -> {{300, 4100}, {94, 101}}, ImageSize -> Large, 
   Axes -> False];

Show[pir, txtir]

enter image description here

dfrx_2.xlsx

$\endgroup$
3
$\begingroup$

A more convenient approach is to use Labeled on selected points:

First a function that labels a point p with its rounded rotated first coordinate:

toLabeled[p_] := Labeled[p, 
   Rotate[Style[Row[{Round[p[[1]], .1], "⟶    "}],  12, Bold], 90 Degree], 
   Below]

Points from ir to be labeled (here these points are extracted from your ir1 ... ir7):

nF = Nearest[ir[[All, 1]] -> Automatic];
selectedpoints = {ir1, ir2, ir3, ir4, ir5, ir6, ir7} /. 
    Rotate[Style[Text[_, pos_], ___], ___] :> ir[[First[nF @ pos[[1]]]]];

A replacement rule that replaces a point p in selectedpoints to toLabeled[p]

labelrule = pt : Alternatives @@ selectedpoints :> toLabeled[pt];

Use labelerule with ReplaceAll to create a modified version of ir:

irnew = ir /. labelrule;

ListLinePlot[irnew, Frame -> True,  ScalingFunctions -> {"Reverse", Automatic},
  FrameStyle -> Directive[Black, 12], 
  FrameTicks -> {{None, None}, {Range[400, 4000, 400], None}}, 
  AspectRatio -> 1/2, 
  FrameLabel -> {{"Transmitancia (%)", None}, 
    {"Número de onda (\!\(\*SuperscriptBox[\(cm\), \(-1\)]\))", None}},
  PlotStyle -> Red, 
  PlotRange -> {{300, 4100}, {94, 101}}, ImageSize -> Large, 
  Axes -> False]

enter image description here

$\endgroup$

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.