1

Right now I have troubles exporting the data out of my contour plot.

Following is the code and the ContourPlot:

M = 1000000;
d = 0.0005;

p[cp_, g_] := Sqrt[(2*Pi*g*M/1716)^2 - (2*Pi*g*M/(cp))^2];
q[cp_, g_] := Sqrt[(2*Pi*g*M/785)^2 - (2*Pi*g*M/(cp))^2];



sy[cp_, g_, p_, 
  q_] := (((2*Pi*g*M/(cp))^2 - q^2)^2) Cos[p*d] Sin[q*d] + 
  4 ((2*Pi*g*M/(cp))^2 ) p q Sin[p*d] Cos[q*d]
sy[cp_, g_] := sy[cp, g, p[cp, g], q[cp, g]];

as[cp_, g_, p_, 
  q_] := (((2*Pi*g*M/(cp))^2 - q^2)^2) Sin[p*d] Cos[q*d] + 
  4 ((2*Pi*g*M/(cp))^2 ) p q Cos[p*d] Sin[q*d]
as[cp_, g_] := as[cp, g, p[cp, g], q[cp, g]];

ContourPlot[ {sy[cp, g]/q[cp, g] == 0, as[cp, g]/p[cp, g] == 0}, {g, 
  0.001, 0.1}, {cp, 0.01, 2000}, PlotPoints -> 100] 

the plotted functions

There is already a posting regarding a similar topic, but I have problems to adapt this to my problem: How to extract data from a contour plot to a text file?

I hope somebody can help or guide me to the correct source.

kglr
  • 394,356
  • 18
  • 477
  • 896
Yasya
  • 13
  • 3

1 Answers1

2

If we use FullForm on the plot itself, and look at the first significant heads, we see that it's just a Graphics object composed of a GraphicsComplex object.

plot = ContourPlot[ {sy[cp, g]/q[cp, g] == 0, as[cp, g]/p[cp, g] == 0}, {g, 0.001, 0.1}, {cp, 0.01, 2000}, PlotPoints -> 100]

{#[[1, 0]], #[[1, 1, 0]]} &@FullForm@plot

{Graphics, GraphicsComplex}

Then we can use Normal on the first part of the plot (The GraphicsComplex), to get something in the familiar Graphics format.

{{},{},{Hue[0.67,0.6,0.6],Line[{<<1>>}]},{Hue[0.906068,0.6,0.6],Line[{{0.001,50.2764},{0.00100432,50.4276},<<934>>,{0.0997525,439.451},{0.1,439.876}}]}}

But we don't want all the color options and other aesthetics, we just want the points that are connected by Line objects.

Cases[%, Line[pts_] :> pts, \[Infinity]]

{{{0.1,1392.03},{0.0999058,1392.04},{0.099875,1392.04},{0.0998437,1392.05},{0.09975,1392.05},<<1421>>,{0.00125,1396.09},{0.00113784,1396.21},{0.00109769,1395.92},{0.001,1396.09}},{<<1>>,<<937>>}}

Or all together

FullForm@plot
Normal@%[[1]] (*// Short[#, 1] &*)
pts = Cases[%, Line[pts_] :> pts, \[Infinity]] (*// Short[#, 2] &*)

Then to export the data in an easily usable file, we simply use

SetDirectory["Your_Directory"]
pts >> "data.m"
ListPlot@<< "data.m"

enter image description here

NonDairyNeutrino
  • 7,810
  • 1
  • 14
  • 29