6
$\begingroup$

I am working with some GPS data for a bike trip I am going on. All the routes are given so it's easy to simply follow the line on your GPS.

I am looking for a way to visually summarize information simply for a quick overview and some "diversion" while riding.

Using the GPS data from a section of the route, I created a list of distances and elevations. Plotting that gives a nice overview of this part of the ride.

ListLinePlot[Transpose[{absoluteDistances/1000., elevations}], 
 Filling -> Axis, PlotRange -> {Automatic, {1000, Max[elevations]}}, 
 AspectRatio -> 0.3] 

Elevation profile

That's a really nice summary, but it would be also really nice to have some information about stuff along the way, label the high points, etc.

Something like....(which I modified manually)

Modified

My question specifically would be, given a list of distances and elevations for a ListLinePlot, how could I then create a "points of interest" list , for example,

POI = {{15, "Bridge"}, {48, "Parking Lot"}} 

and get Mathematica to create my modified plot?

Update

I appreciate the comments I have gotten so far!

As I worked on this, found all kinds of weird things, the GPS data was given partially in m, and partially in km, maybe there is an easy way to deal with that... I messed around and figured out how to change them all to km.

Next issue was that when I wanted to draw a line, say, at 15.3 km, there could potentially be several entries in the GPS list around there, so I had to decide where to put the line. I again messed around, pulled out all entries close to 15.3 km, then took the MINIMUM elevation of all the entries simply because the line drawn looked the best.

I appreciate the answer given that used a plot offset. I decided to put the labels "in" the profile to avoid that problem.

I have a reasonable graph now, but my work, if you call it that, is messy. So I will continue to watch the answers!

I defined two functions, makeText and makeLine

Here is a sample line of made up "points of interest"

poi = {{8.3, "Trailhead"}, {12.6,  "Parking"}, {40, "Gate"}, {60, 
   "Creek"}, {90.2, "Highway"}}

Then this command...

minElev = 1000;

ListLinePlot[pts,
 Filling -> Axis,
 PlotRange -> {Automatic, {minElev, Max[elevations]}}, 
 AspectRatio -> 0.3,
 ImageSize -> 800,
 Epilog -> {
   makeText /@ poi,
   makeLine /@ poi}]

produces a reasonable plot

annotated plot

$\endgroup$
  • $\begingroup$ What would be the source of the "interest" information, and why would Mathematica ever know to "think" that a "Parking lot" was interesting? $\endgroup$ – David G. Stork Apr 21 '15 at 11:58
  • $\begingroup$ Sorry, I am creating a list of points along the way that I want to ADD to the elevations and distances so as I am riding, I could see, I'm here at the bridge and this is where I am in the elevation profile. $\endgroup$ – Tom De Vries Apr 21 '15 at 12:00
  • $\begingroup$ Oh... then just use Epilog -> {Text[Style["Bridge", 14], {40,1400}], Line[{{40, 1100},{40,1400}}]} and so forth. $\endgroup$ – David G. Stork Apr 21 '15 at 12:13
5
$\begingroup$

I would use Epilog option to add the desired annotations. Further, because the annotations are somewhat complex, I would write a function to generate an annotation and map it over the POI list to produce the full set of annotations. Also, some attention must be given to padding the plot at the bottom so the annotations will be visible.

annotation[x_, y0_, y1_, txt_] := 
  With[{dy = .33}, 
    {Line[{{x, y0}, {x, y1}}], Rotate[Text[txt, {x, y0 - dy}], -90 °]}]

poi = {{.25, "Maximum"}, {.75, "Minimum"}};
Plot[Sin[2 π t], {t, 0., 1.},
 PlotRangePadding -> {Automatic, {.85, Automatic}},
 Epilog -> (annotation[#[[1]], -1.2, Sin[2 π #[[1]]], #[[2]]] & /@ poi)]

plot

$\endgroup$
2
$\begingroup$

You can use a combination of Labeled and Filling in ListPlot:

data = Accumulate[RandomReal[{-1, 2}, 250]];
poi = {{60, "Label 1"}, {125, "Label 2"}};
poi2 = Labeled[{#, -15}, Rotate[Style[#2, 16, "Panel", Gray], -Pi/2], Below]&@@@ poi;

ListPlot[{data, poi2}, Joined -> {True, False}, 
 Filling -> {2 -> {{1}, Directive[CapForm["Round"], Thick]}, 1 -> Axis},
 ImagePadding -> {Scaled /@ {0.02, 0.02}, Scaled /@ {.07, .02}}, 
 PlotRangeClipping -> False]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you for that, lots very elegant... I'll have to go through step by step and see if I can figure out what you did, but looks really good $\endgroup$ – Tom De Vries Apr 21 '15 at 14:37

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.