# Extracting the coordinates of a point of interest from a ListDensityPlot

How can I extract coordinates from a list density plot.

Example plot of interest:

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:

-
related Q&A – Kuba Aug 7 '13 at 8:12

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}]}]
]
]

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}, ...}.

-
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]

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

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

(*
{{28.0864, 12.8444}}
*)
-

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}]

-
Are you measuring in the same scale of the Density plot? – Dr. 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 .. :) – Dr. belisarius Aug 8 '13 at 0:00