Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

How can I extract coordinates from a list density plot.

Example plot of interest:

1

I need to place two points on either side of the center white circle and calculate the distance between them. My idea was to use two locators that gives their dynamic coordinates and connect a straight line between them. And calculate the different between them and output it to the user.

How can I do this with?

So far the only thing I figured out is to use a locators as a line to give me dynamic position.

Module[{v1 = {0, 0}, v2 = {2, 0}}, 
 Graphics[{Locator[Dynamic[v1]], Line[{Dynamic[v1], Dynamic[v2]}], 
   Locator[Dynamic[v2]]}, PlotRange -> 3, Frame -> True]]

Screenshot of output:

2

share|improve this question
1  
related Q&A –  Kuba Aug 7 '13 at 8:12

3 Answers 3

up vote 4 down vote accepted

A simple DynamicModule combined with a LocatorPane should give you a first starting point. The line and the distance could be included directly in the ListDensityPlot as dynamic Epilog

DynamicModule[{pt1 = {10., 10.}, pt2 = {30., 30.}}, 
 LocatorPane[Dynamic[{pt1, pt2}], 
  ListDensityPlot[
   Table[x + Sin[3 x + y^2], {x, -3, 3, 0.1}, {y, -3, 3, 0.1}], 
   ColorFunction -> "SunsetColors", PlotRangePadding -> None, 
   Epilog :> 
    Dynamic@{White, Dashed, Line[{pt1, pt2}], 
      Text[Style[Norm[pt1 - pt2], 18], Mean[{pt1, pt2}] + {5, 5}]}]
  ]
]

Mathematica graphics

By the way. If you want to have the real coordinates in your density plot, you should provide that data as {{x1,y1,f1}, {x2,y2,f2}, ...}.

share|improve this answer
2  
Congratulations on breaking 30K! –  Mr.Wizard Aug 7 '13 at 10:30
    
Though your image says its 60x60 the extra white boundary adds it upto 62.5. Is there any way I can avoid that white extra boundary from the image so that my locators give me exact 60 from one vertex to the other ? –  abhilash sukumari Aug 7 '13 at 18:21
    
@abhilashsukumari You can set PlotRangePadding->0 or PlotRangePadding->None to avoid the white space (see also how @belisarius plotted it). –  Jens Aug 7 '13 at 18:59
    
@abhilashsukumari I edited my answer and added the PlotRangePadding option to make it as big as the graphics. –  halirutan Aug 8 '13 at 0:54
dp = DensityPlot[PDF[BinormalDistribution[{35, 23}, {7, 6}, -.7],
                 {x, y}], {x, 0, 50}, {y, 0, 50}, Frame -> False, ImageMargins -> False, 
                 PlotRangePadding -> None, AspectRatio -> Automatic]

Mathematica graphics

Show[Rasterize@dp, 
 Graphics[{Red, Thick, Rotate[Circle[#[[1]], #[[2]]], #[[3]]]}] &@(1 /. 
    ComponentMeasurements[Binarize[dp, .99], {"Centroid", "SemiAxes", "Orientation"}])]

Mathematica graphics

2 (1 /. ComponentMeasurements[Binarize[dp, .999], {"SemiAxes"}]) ((PlotRange /. 
             AbsoluteOptions[dp, PlotRange])[[1, 2]])/(ImageDimensions[bdp][[1]])

(*
  {{28.0864, 12.8444}}
*)
share|improve this answer

Here's a way using Manipulate and two Locators (using the plot from belisarius answer)

dp = DensityPlot[PDF[BinormalDistribution[{35, 23}, {7, 6}, -.7], {x, y}], 
    {x, 0, 50}, {y, 0, 50}, Frame -> False, ImageMargins -> False, 
    PlotRangePadding -> None, AspectRatio -> Automatic];
Manipulate[Show[dp, Graphics[{Line[{p1, p2}],  Inset[Norm[p1 - p2]]}]], 
    {{p1, {10, 10}}, Locator}, {{p2, {20, 20}}, Locator}]

enter image description here

share|improve this answer
    
Are you measuring in the same scale of the Density plot? –  belisarius Aug 7 '13 at 23:24
    
@belisarius - using your density plot map, it has the same scale... –  bill s Aug 7 '13 at 23:57
    
OK, +1 now .. :) –  belisarius Aug 8 '13 at 0:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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