1
$\begingroup$

I currently have two DateListPlots in the same graph, with two different y-axes. I downloaded the package "TwoAxisDateListPlot" to accomplish this with ease. Now I want to be able to trace both of the curves so I can match up their data points. Here's what I've got so far:

data = Import["file.csv", "CSV"]
data2 = Import["file2.csv", "CSV"]
TwoAxisDateListPlot[data,data2,Joined->True,PlotLegends->{"Vbat","Temp"}]

This is the graph:

enter image description here

I'm guessing I should use a Manipulate function for this, but I'm just not that great at using Mathematica yet. Thanks for the help.

EDIT: By "trace," I mean show individual points of the graphs by using a slider to move a point along the curve. Like the trace button on TI calculators. But I'm not sure how I'd do that since the x values are dates.

$\endgroup$
1
  • 2
    $\begingroup$ What do you mean by "trace"? $\endgroup$ Dec 22, 2014 at 20:45

1 Answer 1

2
$\begingroup$

I don't have that package installed, but I will give you an example which can surly be extended to your situation. The basic principle should be clear: You want to select (by Slider or whatever) a certain time and then plot this point dynamically over your DateListPlot. Let's say we have a simple plot of financial data like this

Mathematica graphics

My approach will extract the drawn points from this graphics and gives you the opportunity to trace them. First, you need to understand how Mathematica draws such graphs and this is why I want you to look at the internal representation of a very simple plot. The first part of each Graphics are the graphics primitives which define what is plotted. Look at this

data = {{{2006, 10, 1}, 10}, {{2006, 10, 15}, 12}, 
  {{2006, 10, 30}, 15}, {{2006, 11, 20}, 20}};
DateListPlot[data][[1]]

and see that beside setting some colors, the curve is drawn with a Line primitive. Therefore, what I will do is use Cases to extract the expression matching Line[pts_] in the plot. Then I will use these points and put it inside a Manipulate. For convenience, I will extract the currently used point, max, min, ... values, so that I don't have to write pts[[...]] over and over again.

The rest is to create a new graphics that shows the current point, two helping lines and a label. Everything is then put together with the original plot using Show. I have inserted empty lines in the code, so that you can see the single steps I have explained:

With[{dlp = DateListPlot[FinancialData["IBM", "Jan. 1, 2004"]]},
 With[{pts = First@Cases[dlp, Line[pts_] :> pts, Infinity]},

  Manipulate[

   Module[{mint, maxt, minv, maxv, t, v},
    {{mint, maxt}, {minv, maxv}} = {Min[#], Max[#]} & /@ Transpose[pts];
    {t, v} = pts[[i]];

    Show[dlp,

     Graphics[{ColorData[5, 2], Thickness[.005], PointSize[0.02], 
       Line[{{mint, v}, {t, v}, {t, 0}}], Point[{t, v}],
       Text[Style[DateString[t, {"DateShort"}] <> ": " <> ToString[v], 12,
          Background -> Opacity[.7, White]], {t, v}, {-1, -2}]}]
     ]],

   {i, 1, Length[pts], 1}]
 ]
]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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