I am trying to add some cursors to a plot. I am using LocatorPane and form the cursors by setting the Appearance option. However, I can't seem to find out how big the cursors will be and I need them to rescale according to the data I am using.
Here is a minimum working example. First some data.
data1 = Table[{f, 1/Sqrt[(100^2 - f^2)^2 + 0.1 f^2]}, {f, 0, 300,
0.1}];
data2 = Table[{f, (Sqrt[0.1] 100)/
Sqrt[(100^2 - f^2)^2 + 0.1 f^2]}, {f, 0, 300, 0.1}];
Here is a dynamic module which plots the data and provides the cursors.
ClearAll[curPlot];
curPlot[] := DynamicModule[{pt1 = {10, 0.02}, pt2 = {200, 0.02}},
LocatorPane[
Dynamic[{pt1,
pt2}, (pt1 = {#[[1, 1]], 0.02}; pt2 = {#[[2, 1]], 0.02}) &],
Dynamic@
ListPlot[data, Joined -> True, PlotRange -> All, Frame -> True,
Axes -> False, ImageSize -> 6 72],
Appearance ->
Graphics[{Red, Line[{{0, 0}, {0, 1}}]},
ImageSize -> {Automatic, 3 72 /GoldenRatio}]
]
]
If I set
data = data1;
and then
curPlot[]
I get
If I now change to the other data by setting
data = data2;
The plot changes to
I want the plot to change dynamically like this when data is changed.
How do I make the cursor length occupy the whole height of the plot? I have been trying to see if it is involved with the ImageSize but can't work it out at the moment.
I actually need a more advanced version with a log plot. The code is now
ClearAll[curPlot2];
curPlot2[] := DynamicModule[{pt1 = {10, 0.02}, pt2 = {200, 0.02}},
LocatorPane[
Dynamic[{pt1,
pt2}, (pt1 = {#[[1, 1]], 0.02}; pt2 = {#[[2, 1]], 0.02}) &],
Dynamic@
ListLogPlot[data, Joined -> True, PlotRange -> All,
ImageSize -> 6 72, Frame -> True],
Appearance ->
Graphics[{Red, Line[{{0, 0}, {0, 1}}]},
ImageSize -> {Automatic, 3 72/GoldenRatio }]
]
]
With data = data1;
I get nothing but with data = data2;
I get:
I really need to understand how the locator is formed and positioned. Thanks for any help.