1
$\begingroup$

Hello i have made a graph with a oscillating behavior but i need to highlight the maximum value of the oscillation because i will use that value like a threshold and I need to put a horizontal line in that particular spot of the graph. So for example, let say that i have the next data:

data = Table[{i, Sin[i]}, {i, 0, 4 Pi, Pi/100}]

Then I plot the data with the next command:

 ListLinePlot[data] 

And I get the next graph:

enter image description here

So i need to put an horizontal line in the y= 1 coordinate because that's the max value of the curves, how can i do that?

$\endgroup$
5
$\begingroup$

The answer, funnily enough, is in one of your tags:

ListLinePlot[Table[{i, Sin[i]}, {i, 0, 4 Pi, Pi/100}], GridLines -> {None, {1}},
             GridLinesStyle -> Directive[AbsoluteThickness[3/2], ColorData[97, 2]]
             Method -> {"GridLinesInFront" -> True}]

sine and line


It's always nice to have alternatives:

ListLinePlot[Table[{i, Sin[i]}, {i, 0, 4 Pi, Pi/100}], 
             Epilog -> {Directive[AbsoluteThickness[2], ColorData[97, 2]], 
                        InfiniteLine[{0, 1}, {1, 0}]}]
$\endgroup$
2
$\begingroup$
ListLinePlot[data, Epilog -> Line[{{0, 1}, {4 Pi, 1}}]]

enter image description here

$\endgroup$
  • $\begingroup$ For this problem 1 is the right number. I think you want to generalize it and maybe use Max[data[[All,2]]], possibly defined using With so you don't compute it twice. $\endgroup$ – Jack LaVigne Oct 20 '15 at 18:14

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.