1
$\begingroup$

I want to take some points, place them onto a graph and then use the locator pane. I then want to take the new locations that the user has moved the points too and remove the y coordinate and use just the x coordinate and plot that.

I seem to be unable to update datasetx with the point data whatever I do. I have read up on DynamicModule but that hasn't helped. Any recommended reading would be appreciated.

DynamicModule[{point1 = {4, 4}, point2 = {4.5, 4.5}, point3 = {5, 5}, point4 = {6, 6}, point5 = {6.5, 6.5}},

{
 dataset = {point1, point2, point3, point4, point5};

 p1 = LocatorPane[Dynamic[dataset], Dynamic[ListPlot[dataset, PlotRange -> {{0, 10}, {0, 10}} ]]];

(*just take the x part*) 

 datasetx =   {{point1[[1]],0},{point2[[1]],0},{point3[[1]],0},{point4[[1]], 0},{point5[[1]],0}};

 xgraph = Dynamic[ListPlot[{datasetx}, PlotRange -> {{0, 10}, {0, 10}}]];


 GraphicsRow[{{p1}, xgraph}, Dynamic[datasetx]

 }]
$\endgroup$
2
$\begingroup$

Something like this?

DynamicModule[
    {point1 = {4, 4}, point2 = {4.5, 4.5}, point3 = {5, 5}, 
     point4 = {6, 6}, point5 = {6.5, 6.5}}, 
   dataset = {point1, point2, point3, point4, point5}; 
   p1 = 
     LocatorPane[
        Dynamic[dataset], 
        Dynamic[ListPlot[dataset, PlotRange -> {{0, 10}, {0, 10}}]]]]; 
GraphicsRow[
  {p1, 
   Dynamic[
     ListPlot[datasetx = dataset /. {x_, y_} :> {x, 0}, 
       PlotStyle -> PointSize[0.03], PlotRange -> {{0, 10}, {-1, 1}}]]}, 
   ImageSize -> Large]

enter image description here

$\endgroup$
1
$\begingroup$

Algohi's post answers the above question while adhering to the OP's code very closely. I suggest abandoning such adherence for two reasons.

  1. Simpler code.
  2. Better localization of variables.

Here is what I get by taking Algohi's work as a basis, but simplifying it without worrying about maintaining the structure of the OP's code:

DynamicModule[{locators, plot, pts},
  pts = {{4, 4}, {4.5, 4.5}, {5, 5}, {6, 6}, {6.5, 6.5}};
  locators = 
    LocatorPane[
      Dynamic @ pts, 
      Dynamic @ ListPlot[pts, PlotRange -> {{0, 10}, {0, 10}}]];
  plot = 
     Dynamic @ 
       ListPlot[pts /. {x_, y_} :> {x, 0},
         PlotStyle -> PointSize[0.03], PlotRange -> {{0, 10}, {-1, 1}}];
  GraphicsRow[{locators, plot}, ImageSize -> Large]]

The result of evaluating the above code looks and behaves exactly like Algohi's solution.

$\endgroup$

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.