3
$\begingroup$

I have a set of data obtained by NDSolve. After I plot it, I want to indicate some feature of the curves. For example, I want to link the local minimum-value points between these curves by dotted line to highlight the track. First, I import the data:

data1 = Import["C:\\Users\\...\\Desktop\\data1.dat"];
data2 = Import["C:\\Users\\...\\Desktop\\data2.dat"];
data3 = Import["C:\\Users\\...\\Desktop\\data3.dat"];

then, plot them

g1 = ListLinePlot[data1];
g2 = ListLinePlot[data2];
g3 = ListLinePlot[data3];
Show[g1, g2, g3, PlotRange -> All]

I get the following plot

enter image description here

What I want to do is to link the local min-value point by dashed line. Is there any simply method by Mathematica to do this job? Should I make use of FindMinimum and FindMinValue, but I don't know how to combine them. The objective I want to obtain is as follows which is got by hand:). enter image description here

Yes, as answered by @Oska, whose code can handle many cases. But fail to treat the following case in which there are several local minimum-value points in a single curve. This is the my_data.

Using Oska's code

data1 = Import["C:\\...\\plot1_4sqrt(2)pi.dat"];
data2 = Import["C:\\...\\plot2_4sqrt(2)pi.dat"];
data3 = Import["C:\\...\\plot3_4sqrt(2)pi.dat"];

mins = Function[d, 
d[[#]] & /@ (Sort[
   First@First@
       Position[d, #] & /@ (RankedMin[Last /@ d, #] & /@ {1, 
       2})])] /@ {data1, data2, data3};
ListLinePlot[{data1, data2, data3}, 
Epilog -> {Arrowheads[0.02], 
Arrow /@ (Thread@{(First /@ mins), 
    RotateLeft@(First /@ mins)})[[;; -2]], 
Arrow /@ (Thread@{(Last /@ mins), 
    RotateLeft@(Last /@ mins)})[[;; -2]]}
]

I will get enter image description here

As can be seen, the code fails to find the local min-value points on the first curve. What I try to get is as follow. I am confusing that why the code can find the local min-value point of the other two curves but fails to the first curve? enter image description here

$\endgroup$
  • $\begingroup$ You should consider doing a little bit of work and find the minima that you desire on your own. $\endgroup$ – Öskå Oct 16 '14 at 13:56
  • $\begingroup$ Yes, @Öskå. Thanks a LOT :). But could you give me some hints on why this code can not find the two local min-value points of the first curve but can find that of the other two similar curves. $\endgroup$ – Enter Oct 16 '14 at 14:42
  • $\begingroup$ You may consider searing on mathematica.SE: see here :) $\endgroup$ – Öskå Oct 16 '14 at 14:52
4
$\begingroup$

I will let you play with the style but here is a beginning:

data1 = Import["~/Downloads/data/data1.dat"];
data2 = Import["~/Downloads/data/data2.dat"];
data3 = Import["~/Downloads/data/data3.dat"];
mins = Function[d, 
   d[[#]] & /@ (Sort[
      First@First@Position[d, #] & /@ (RankedMin[Last /@ d, #] & /@ {1, 2})])] /@ 
   {data1, data2, data3}

ListLinePlot[{data1, data2, data3}, 
 Epilog -> {Red, Line[First /@ mins], Line[Last /@ mins]}]

Mathematica graphics

Regarding the series of arrows:

ListLinePlot[{data1, data2, data3}, 
 Epilog -> {Red, 
   Arrow /@ (Thread@{(First /@ mins), RotateLeft@(First /@ mins)})[[;; -2]], 
   Arrow /@ (Thread@{(Last /@ mins), RotateLeft@(Last /@ mins)})[[;; -2]]},]

Mathematica graphics

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks, @Oska! Is there any possible to add a series of arrows on the redline? I tried this code p0 = ListLinePlot[{data1, data2, data3}, Epilog -> {Red, Dashing[0.02], Line[First /@ mins], Line[Last /@ mins]}];p0 /. Line[x_] :> {Arrowheads[{0, .05, .05, 0}], Arrow[x]}. But I also added arrows on the three curve where I do not need arrow. $\endgroup$ – Enter Oct 16 '14 at 3:05
  • $\begingroup$ @lxy Please check the update :) $\endgroup$ – Öskå Oct 16 '14 at 10:09
  • $\begingroup$ Hi,@Oska,thank you for your helpful answer. But it might have a bug. I am confusing that why the code can find the local min-value point of the some curves but fails to the other curves? Could you pls see my post again which has been updated. Thank you for your time! $\endgroup$ – Enter Oct 16 '14 at 13:54

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.