2
$\begingroup$

Is there some clever way to generate a TikZ plot sequence of draw coordinates in Mathematica? The following commands works fairly well

y[x_] := Log[2, (2 x - 200)/(x - 200)]
Table[{i, y[i]}, {i, 201, 2000, 10}] // N

but results in the output

{{201., 7.65821}, {211., 4.33498},...

I can post-process it in a text editor but it would better if it could be output in Mathematica as

(201., 7.65821)--
(211., 4.33498)--
(221., 3.52655)--
(231., 3.07923)--
(241., 2.78200)--
...

or something similar, to be easily used with the TikZ draw-command. I could loop through the list and 'format';

Clear[i, y];
y[x_] := Log[2, (2 x - 200)/(x - 200)];
coordinates = Table[{i, y[i]}, {i, 201, 2000, 10}] // N;
tikzlist = {};
For[i = 1, i <= Length[coordinates], i++,
 x = coordinates[[i]][[1]];
 y = coordinates[[i]][[2]];
 tikzlist = 
  tikzlist <> "(" <> ToString[x] <> "," <> ToString[y] <> ")--";
 ]
tikzlist = StringTake[tikzlist, StringLength[tikzlist] - 2] <> ";"

but perhaps there is some shorter one-line command that does the job better and more efficiently. TIA.

$\endgroup$
4
$\begingroup$

You can use TextString with its ListFormat option to directly format the list as needed, without any postprocessing:

TextString[
 TextString[#, ListFormat -> {"(", ", ", ")"}] & /@ tab1,
 ListFormat -> {"", "--\n", ""}
 ]
(* 
 (201., 7.65821)--
 (211., 4.33498)--
 (221., 3.52655)--
 (231., 3.07923)--
 (241., 2.782)--
 …
*)
$\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.