-1
$\begingroup$

I have the following code:

data = Transpose @ {
          {2, 4, 7, 2, 19, 2, 4, 6, 2, 8, 5},
          {222, 250, 213, 150, 120, 154, 245, 235, 200, 100, 450}
        }; 
glm = GeneralizedLinearModelFit[data, x, x, ExponentialFamily -> "Gamma"];
h = glm["HatDiagonal"];
hP = FindPeaks[h, 0, 0, 0.5]
ListLinePlot[
  {h, hP}, 
  Joined -> {True, False}, 
  PlotRange -> {{0, 25}, {0, 1}}, AxesLabel -> {"Index", "h"}, 
  AxesStyle -> Directive[Black, FontSize -> 14], TicksStyle -> Black, 
  PlotStyle -> {Automatic, {Black, PointSize[0.03]}}, 
  Epilog -> Line[{{0, 0.5}, {25, 0.5}}]
]

This generates the following plot:

Mathematica graphics

Here is my question: How do we show the case number which crosses the Epilog line instead of Point? My Question is not to show the two intersection points but the point which crosses the Epilog line. here this point is 5th. How I show the case 5 as indicated on a plot but not showing black bold point?.

$\endgroup$
2
  • 3
    $\begingroup$ We can't run your code because we don't have your data, so we can't help you. Please provide data, make sure that the code runs as posted. Also, removing all the superfluous formatting from your ListLinePlot will make your code more readable. $\endgroup$
    – MarcoB
    Mar 3 '16 at 17:14
  • $\begingroup$ Possible duplicate of Labeling points of intersection between plots $\endgroup$
    – MarcoB
    Mar 3 '16 at 18:29
4
$\begingroup$

You should look at the following existing answers that pose essentially the same problem you have:

You can modify your code as follows:

ListLinePlot[

  {h, hP}, Joined -> {True, False},

  Mesh -> {{0.5}},
  MeshFunctions -> {(#2&)},
  MeshStyle -> Directive[Red, PointSize[0.02]],

  Epilog -> Line[{{0, 0.5}, {25, 0.5}}],

  PlotRange -> {{0, 25}, {0, 1}}, AxesLabel -> {"Index", "h"}, 
  AxesStyle -> Directive[Black, FontSize -> 14], TicksStyle -> Black, 
  PlotStyle -> {Automatic, {Black, PointSize[0.03]}}

]

Mathematica graphics


Here's one way to label the point that goes above the threshold:

ListLinePlot[
  h,

  Epilog -> {
    Line[{{0, 0.5}, {25, 0.5}}],
    Text[Style[hP[[1, 1]], 14, Red], First@hP + {0.05, 0.05}]
    },

  PlotRange -> {{0, 25}, {0, 1}}, AxesLabel -> {"Index", "h"}, 
  AxesStyle -> Directive[Black, FontSize -> 14], TicksStyle -> Black
]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ dear how i show the case number 5 instead of black bold point? only determining one point or points which croses Epilog line (Cut-point) but not two intersection points. In this case we want to show the 5th case on a plot $\endgroup$
    – Amin
    Mar 3 '16 at 18:29
  • 2
    $\begingroup$ (+1) you could use {#2&} for the MeshFunctions setting. $\endgroup$
    – kglr
    Mar 3 '16 at 18:34
  • $\begingroup$ @kglr D'oh! Of course! Thank you for pointing it out, I amended the answer. $\endgroup$
    – MarcoB
    Mar 3 '16 at 18:36

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