Message Boards Message Boards

1
|
9115 Views
|
7 Replies
|
5 Total Likes
View groups...
Share
Share this post:

Use FindPeaks in a DateListPlot?

Posted 7 years ago

Hi All,

A very simple question but I can't find why 'FindPeaks' are not working in DateListPlot. What is wrong?

Thanks in advance !

fakedata = {{{2015, 3, 25}, 130}, {{2015, 3, 26}, 
    132}, {{2015, 3, 27}, 132}, {{2015, 3, 30}, 133}, {{2015, 3, 31}, 
    132}, {{2015, 4, 1}, 131}, {{2015, 4, 2}, 131}, {{2015, 4, 3}, 
    131}, {{2015, 4, 6}, 131}, {{2015, 4, 7}, 131}, {{2015, 4, 8}, 
    129}, {{2015, 4, 9}, 132}, {{2015, 4, 10}, 133}, {{2015, 4, 13}, 
    132}, {{2015, 4, 14}, 131}, {{2015, 4, 15}, 131}, {{2015, 4, 16}, 
    128}, {{2015, 4, 17}, 125}, {{2015, 4, 20}, 127}, {{2015, 4, 21}, 
    127}};

peaks = FindPeaks[Take[fakedata[[All, 2]]]]

DateListPlot[
 fakedata
 , PlotRange -> {Automatic, {123, 135}}
 , Epilog -> {Red, PointSize[0.02], Point[peaks]}
 ]

enter image description here

POSTED BY: Jos Klaps
7 Replies

Dear Chris,

Thanks for your reply, tip and help !

Best Regards,....Jos

POSTED BY: Jos Klaps

Dear All,

Thanks again for your reply and interest.

@Chris P, very interested and usefull information. Thanks.

For your information only: The calculated 'FindPeaks' and 'Dates' at the top only (x-axis 2).

fakedata = {{{2015, 3, 25}, 130}, {{2015, 3, 26}, 
    132}, {{2015, 3, 27}, 132}, {{2015, 3, 30}, 133}, {{2015, 3, 31}, 
    132}, {{2015, 4, 1}, 131}, {{2015, 4, 2}, 131}, {{2015, 4, 3}, 
    131}, {{2015, 4, 6}, 131}, {{2015, 4, 7}, 131}, {{2015, 4, 8}, 
    129}, {{2015, 4, 9}, 132}, {{2015, 4, 10}, 133}, {{2015, 4, 13}, 
    132}, {{2015, 4, 14}, 131}, {{2015, 4, 15}, 131}, {{2015, 4, 16}, 
    128}, {{2015, 4, 17}, 125}, {{2015, 4, 20}, 127}, {{2015, 4, 21}, 
    127}};

data = Take[fakedata[[All, 2]]];

peaks = FindPeaks[data]

ListLinePlot[
 data
 , PlotRange -> {Automatic, {123, 135}}
 , Epilog -> {Red, PointSize[0.02], Point[peaks]}
 , GridLines -> Automatic
 , Frame -> True
 , FrameTicks -> {{True, 
    None}, {True, {{4, "30 Mar\n2015"}, {13, "10 Apr \n2015"}, {19.5, 
      "20 Apr\n2015"}}}}
 ]

enter image description here

Regards,....Jos

POSTED BY: Jos Klaps
Posted 7 years ago

You have to be very careful here with this approach, one might think that the time scale is linear here which is not, because your data are not regularly sampled. For example, as you can see the distances (30th of March - 10th of April) and (10th of April - 20th of April) which actually correspond both to 10 days, do not appear the same in the graphic !

But your approach will work very well as soon as you have data for each day !

Regards,

Chris

POSTED BY: Chris P
Posted 7 years ago
POSTED BY: Chris P

Dear Kapio and Sander,

Thanks for your reply and help.

@Sander, your proposal works perfect. Thanks again.

Please, one more question: do you know how the peaks (by slope?) are calculated. Where can I find the equations in MM?

Regards,....Jos

POSTED BY: Jos Klaps
POSTED BY: Sander Huisman
POSTED BY: Kapio Letto
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract