Message Boards Message Boards

0
|
4123 Views
|
11 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Displaying coordinates on graph

Posted 2 years ago

Dear Members, I require that the coordinates display on the graph as the intersection move dynamically. Thank you for your usual help.

Manipulate[ContourPlot[{
   -5 v1 - 82 v2 == (v3 - 522),
   -1.25 v1 - 4.45 v2 == (v4 - 263)},
  {v1, 10, 50},
  {v2, 2, 5},
  PlotLegends -> Placed[{"a58", "a60"}, Above],
  FrameLabel -> {"X", "Y"},
  Axes -> True,
  Frame -> True],
 {{v3, 94, "a58"}, 6, 892, Appearance -> "Open"},
 {{v4, 165, "a60"}, 165, 270, Appearance -> "Open"},
 ControlPlacement -> Left]
POSTED BY: Ma noj
11 Replies
Posted 2 years ago

Dear Prof. Milton, Thank you very much. Works wonderfully

POSTED BY: Ma noj
num = NumberForm[#, {Infinity, 3}] &;

Manipulate[
 isect = {x, y} /. 
    NSolve[{-5 x - 82 y == v3 - 522, -1.25 x - 4.45 y == 
       v4 - 263}, {x, y}] // First;
 coords = Grid[Thread[{{"X:", "Y:"}, num /@ isect}], Alignment -> "."];

 ContourPlot[
  {-5 v1 - 82 v2 == (v3 - 522), -1.25 v1 - 4.45 v2 == (v4 - 263)},
  {v1, 10, 50}, {v2, 2, 5},
  PlotLegends -> Placed[{"a58", "a60"}, Above], 
  FrameLabel -> {"X", "Y"}, Axes -> True, Frame -> True, 
  Epilog -> 
   First@ListPlot[{Callout[isect, coords]}, 
     PlotRange -> {{10, 50}, {2, 5}}, 
     PlotStyle -> Directive[Large, Red]]]
 ,
 {{v3, 94, "a58"}, 6, 892, Appearance -> "Open"},
 {{v4, 165, "a60"}, 165, 270, Appearance -> "Open"},
 {isect, None},
 {coords, None},
 Delimiter,
 Spacer@{0, 50}, 
 Item[Style[Dynamic[coords], 14] // Framed, Alignment -> Center],
 ControlPlacement -> Left,
 TrackedSymbols :> {v3, v4}]

Using Epilog with Callout you can have your coords in the plot enter image description here

POSTED BY: Martijn Froeling
Posted 2 years ago

Dear Prof. Froeling, Thank you very much for your suggestion. I'll implement same in the code.

POSTED BY: Ma noj
Posted 2 years ago

Try the code below. Besides the 3 decimals issue I have also moved the coordinate display to the center, should you think that looks better.

Manipulate[
    isect = {x, y} /. NSolve[{-5 x - 82 y == v3 - 522, -1.25 x - 4.45 y == v4 - 263}, {x, y}] // First;
    isect = NumberForm[#, {Infinity, 3}] & /@ isect;
    coords = Grid[{{"X:", First@isect}, {"Y:", Last@isect}}, Alignment -> "."];
    ContourPlot[
     {-5 v1 - 82 v2 == (v3 - 522), -1.25 v1 - 4.45 v2 == (v4 - 263)},
     {v1, 10, 50}, {v2, 2, 5},
     PlotLegends -> Placed[{"a58", "a60"}, Above], FrameLabel -> {"X", "Y"},
     Axes -> True, Frame -> True
    ],
    {{v3, 94, "a58"}, 6, 892, Appearance -> "Open"},
    {{v4, 165, "a60"}, 165, 270, Appearance -> "Open"},
    {isect, None}, {coords, None},
    Delimiter, Spacer@{0, 50},
    Item[Style[Dynamic[coords], 14] // Framed, Alignment -> Center],
    ControlPlacement -> Left, TrackedSymbols :> {v3, v4}
 ]
POSTED BY: Hans Milton
Posted 2 years ago

Thanks for prompt reply Prof. However as I included in the program, It doesn't working. Kindly revert me for resolve. Thanks.

Manipulate[With[{v3 = 6, v4 = 190},
  isect = {x, y} /.
      NSolve[
       {-5 x - 82 y == v3 - 522,
        -1.25 x - 4.45 y == v4 - 263},
       {x, y}] // First // NumberForm[#, {Infinity, 2}] &;
  coords = 
   Grid[{{"X:", First@isect}, {"Y:", Last@isect}}, Alignment -> "."]];

 ContourPlot[
  {-5 v1 - 82 v2 == (v3 - 522),
   -1.25 v1 - 4.45 v2 == (v4 - 263)},
  {v1, 10, 50}, {v2, 2, 5},
  PlotLegends -> Placed[{"a58", "a60"}, Above],
  FrameLabel -> {"X", "Y"},
  Axes -> True, Frame -> True],
 {{v3, 94, "a58"}, 6, 892, Appearance -> "Open"},
 {{v4, 165, "a60"}, 165, 270, Appearance -> "Open"},
 {isect, None}, {coords, None},
 Delimiter, Spacer@{0, 50},
 Style[Dynamic[coords], 18] // Framed, ControlPlacement -> Left]
POSTED BY: Ma noj
Posted 2 years ago

Dear Sir, Trust you are well. In the previous program, I've been trying to set the solution to be displayed at 3 decimal places. I've tried with:

NSolve[{-5 x - 82 y == v3 - 522, -1.25 x - 4.45 y == v4 - 263}, {x, 
  y}, Reals, 3]

NSolve[{-5 x - 82 y == v3 - 522, -1.25 x - 4.45 y == v4 - 263}, {x, 
  y}, WorkingPrecision -> 3]

But none are giving the output at 3 decimal places. Grateful for your time and your help. Thanks and regards.

POSTED BY: Ma noj
Posted 2 years ago

You can use NumberForm. e.g.

With[{v3 = 6, v4 = 190}, 
   {x, y} /. 
    NSolve[{-5 x - 82 y == v3 - 522, -1.25 x - 4.45 y == v4 - 263}, {x, y}]] // First // 
    NumberForm[#, {Infinity, 3}] &
(* {45.979, 3.489} *)

As with most form wrappers, the result cannot be used in subsequent computations, it is for display only. So used NumberForm on First@isect and Last@isect.

POSTED BY: Rohit Namjoshi
Posted 2 years ago

OK, here is a version with coordinates at the left

Manipulate[
    isect = {x, y} /. NSolve[{-5 x - 82 y == v3 - 522, -1.25 x - 4.45 y == v4 - 263}, {x, y}] // First;
    coords = Grid[{{"X:", First@isect}, {"Y:", Last@isect}}, Alignment -> "."];
    ContourPlot[
     {-5 v1 - 82 v2 == (v3 - 522), -1.25 v1 - 4.45 v2 == (v4 - 263)},
     {v1, 10, 50}, {v2, 2, 5},
     PlotLegends -> Placed[{"a58", "a60"}, Above], FrameLabel -> {"X", "Y"},
     Axes -> True, Frame -> True
    ],
    {{v3, 94, "a58"}, 6, 892, Appearance -> "Open"},
    {{v4, 165, "a60"}, 165, 270, Appearance -> "Open"},
    {isect, None}, {coords, None},
    Delimiter, Spacer@{0, 50},
    Style[Dynamic[coords], 14] // Framed,
    ControlPlacement -> Left, TrackedSymbols :> {v3, v4}
 ]
POSTED BY: Hans Milton
Posted 2 years ago

Dear Sir, Thank you very much. Grateful for your help.

POSTED BY: Ma noj
Posted 2 years ago

Dear Sir, Thank you for your response I am trying to get something like the example image attached. The coordinates can be either on the graph itself or on the left

enter image description here

Attachment

Attachments:
POSTED BY: Ma noj
Posted 2 years ago
Manipulate[
    intersection = NSolveValues[{-5 x - 82 y == v3 - 522, -1.25 x - 4.45 y == v4 - 263}, {x, y}];
    ContourPlot[
     {-5 v1 - 82 v2 == (v3 - 522), -1.25 v1 - 4.45 v2 == (v4 - 263)},
     {v1, 10, 50}, {v2, 2, 5},
     PlotLegends -> Placed[{"a58", "a60"}, Above], FrameLabel -> {"X", "Y"},
     Axes -> True, Frame -> True, PlotLabel -> intersection
    ],
    {{v3, 94, "a58"}, 6, 892, Appearance -> "Open"},
    {{v4, 165, "a60"}, 165, 270, Appearance -> "Open"},
    {intersection, None},
    ControlPlacement -> Left
 ]
POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract