# Extract data from a Parametric2D plot

I'm trying to extract the data from a parametric plot via the following:

Subscript[\[Epsilon], e] = 0.0005;
Subscript[R, 0] = 15;
f[\[Theta]_, \[Phi]_] :=
1 + (4 Subscript[\[Epsilon], e])/(1 -
3 Subscript[\[Epsilon], e]) (Cos[\[Theta]]^4 +
Sin[\[Theta]]^4 (1 - 2 Sin[\[Phi]]^2 Cos[\[Phi]]^2));
x = Subscript[R,
0] (f[\[Theta], \[Phi]] Sin[\[Theta]] Cos[\[Phi]] +
D[f[\[Theta], \[Phi]], \[Theta]] Cos[\[Theta]] Cos[\[Phi]] - (D[
f[\[Theta], \[Phi]], \[Phi]] Sin[\[Phi]])/Sin[\[Theta]]);
y = Subscript[R,
0] (f[\[Theta], \[Phi]] Sin[\[Theta]] Sin[\[Phi]] +
D[f[\[Theta], \[Phi]], \[Theta]] Cos[\[Theta]] Sin[\[Phi]] + (D[
f[\[Theta], \[Phi]], \[Phi]] Cos[\[Phi]])/Sin[\[Theta]]);
z = Subscript[R,
0] (f[\[Theta], \[Phi]] Cos[\[Theta]] -
D[f[\[Theta], \[Phi]], \[Theta]] Sin[\[Theta]]);


Now, Parametric2D gives me the desired figure.

ParametricPlot[{x, y}, {\[Theta], 0, 2 \[Pi]}, {\[Phi], 0,
2 \[Pi]}, PlotStyle -> None, MeshFunctions -> {#3 &},
Mesh -> {{{\[Pi]/2, Directive[Opacity[1], Blue, Thick]}}}]


Next I need to save the data, and I do the following

data = Cases[
ParametricPlot[{x, y}, {\[Theta], 0, 2 \[Pi]}, {\[Phi], 0,
2 \[Pi]}, PlotStyle -> None, MeshFunctions -> {#3 &},
Mesh -> {{{\[Pi]/2, Directive[Opacity[1], Blue, Thick]}}}],
Line[data_] :> data, -4, 1][[1]];
SetDirectory[NotebookDirectory[]];
Export["Groov_pro_Diff_THAf.txt", data, "Table"]


Through the above code, although I generate a txt file, I get the error

Part1 of {} does not exist


I have no issues with the plot, ParametricPlot[...] command gives me the correct figure, but not during saving the data. Here I would like to save the data as two columns only. Can anyone suggest how to extract the data in such a case?

For such situations Reap and Sow are quite useful:
data = Reap[ParametricPlot[{x, y}, {\[Theta], 0, 2 \[Pi]}, {\[Phi], 0, 2 \[Pi]}, PlotStyle -> None, MeshFunctions -> {#3 &}, Mesh -> {{{\[Pi]/2, Directive[Opacity[1], Blue, Thick]}}}, EvaluationMonitor :> Sow[{\[Theta], \[Phi], x, y}]]][[2]]

This returns list {\[Theta], \[Phi], x, y}. If you want to save only {x,y} use it inside Sow instead.
• That is you want only list of {{x_1,y_1},...,{x_N,y_N}} ? If so, using Sow[{x, y}] should work. For exporting indeed either export data[[1]] or in the definition of data use [[2,1]] at the end. Commented Apr 28, 2021 at 13:16
• My answer was really about how to extract data from a plot. If you want to extract only some specific points, then this will depend on what exactly is your goal (I assume it is bit more than this example, as otherwise you'd probably just generate a table with points, rather than going through plot). Anyway, in this example you could use If[x^2 + y^2 >= 15^2, Sow[{x, y}]] Commented Apr 28, 2021 at 13:49
• Yes, this is what I meant: data = Reap[ParametricPlot[{x, y}, {\[Theta], 0, 2 \[Pi]}, {\[Phi], 0, 2 \[Pi]}, EvaluationMonitor :> If[x^2 + y^2 >= 15^2, Sow[{x, y}]]]][[2, 1]] Commented Apr 28, 2021 at 14:00