Group Abstract Group Abstract

Message Boards Message Boards

0
|
67 Views
|
5 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Why does the coordinate value containing fractions in this code show a formatting error when display

Posted 2 days ago
{pM = {3/2, Sqrt[3]/2}, pA = {0, Sqrt[3]}, pB = {3, 0}};
    ContourPlot[Evaluate@{x^2/9 + y^2/3 == 1}, {x, -3.5, 4}, {y, -2, 3}, 
     Epilog -> {MapThread[
        Text[#1 <> ToString@#2, #2, {-1, -1}] &, {{"M", "A", 
          "B"}, {pM, {0, 2}, {3, 0}}}]}, Frame -> False, Axes -> True, 
     AspectRatio -> Automatic, AxesLabel -> {"x", "y"}, 
     AxesStyle -> Arrowheads@0.025, PlotLegends -> "Expressions"]

enter image description here

The goal is to have the coordinate values of point M displayed as exact values {3/2, Sqrt[3]/2} in the image. How should the code be modified?

POSTED BY: Wen Dao
5 Replies
Posted 2 days ago

This is just a consequence of using ToString on an expression that isn't simple "one dimensional" text. Just look at the output of

ToString[{3/2, Sqrt[3]/2}]

So, you either need to force your expressions to be "one dimensional" or you need to just not use ToString. For examples:

Epilog -> {MapThread[Text[#1 <> ToString[#2, InputForm], #2, {-1, -1}] &, {{"M", "A", "B"}, {pM, {0, 2}, {3, 0}}}]}

Epilog -> {MapThread[Text[Row[{#1, #2}, " : "], #2] &, {{"M", "A", "B"}, {pM, {0, 2}, {3, 0}}}]}
POSTED BY: Eric Rimbey

One more variation:

MapThread[Text[TraditionalForm[#1 @@ #2], #2, {-1, -1}] &,
 {{M, A, B}, {pM, {0, 2}, {3, 0}}}]
POSTED BY: Gianluca Gorni
Posted 1 day ago

This method is great, and it's more concise. Thank you for your help!

POSTED BY: Wen Dao
Posted 1 day ago
Epilog -> {MapThread[
   Text[TraditionalForm@
      Row[{#1, 
        "(" <> ToString[TraditionalForm@#2[[1]]] <> "," <> 
         ToString[TraditionalForm@#2[[2]]] <> 
         ")"}], #2, {-1, -1}] &, {{"M", "A", "B"}, {pM, pA, pB}}]}

According to Eric Rimbey's answer, the output format of handwritten coordinates can be slightly modified.

POSTED BY: Wen Dao
Posted 1 day ago

The problem has been solved in two ways. Thank you very much for your help.

POSTED BY: Wen Dao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard