# Export Graph data in text format

How can we export the data in excel of the following streamlines and contour plots to plot in Tecplot?

StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3},PlotLegends -> Automatic]


and isotherms, contourplot

ContourPlot[Cos[x]+Cos[y], {x, 0, 4 Pi}, {y, 0, 4Pi}]

• Cases[yourStreamPlot, a_Arrow :> a[], All] will return a list of the points describing each one of the arrows in that plot. You could export that to various formats using Export. It will then be up to you to adapt that so you can use Tecplot (with which I am not familiar). The ContourPlot is more complicated because color matters there, but if you just want the contour lines: Cases[Normal@yourContourPlot, l_Line :> l[], All]. What do you need to do in Tecplot specifically? Maybe it could be accomplished in MMA without exporting. – MarcoB Mar 5 at 15:34
• Does StreamPlot not just use the derivative in the x and y direction? Could you not just export the data that way? – Teabelly Mar 7 at 13:18
• @Teabelly i Want to export the data results of fluid flow model. The code of that problem is too large that's why here I mention the simple example so I will get the idea of how to export the data? – Mathematicain Mar 7 at 16:28
• Can you post the equation please? – Teabelly Mar 7 at 17:13
• @Teabelly Please check this code i want to export data of streamlines and isotherms. drive.google.com/file/d/1WDH2PUMahuKMn1PtnaqYPSl1XCimgdXm/… – Mathematicain Mar 7 at 18:09

## StreamPlot - Using Excel

### Preparing Data

Here is the procedure you should follow:

StreamPlot[{eq1[x,y], eq2[x,y]}, {x, ...}, {y, ...}]


should be written as:

Flatten[#, 1] &@ Table[{x, y, eq1[x,y], eq2[x,y]}, {x, ...}, {y, ...}]


Because writing on a single spreadsheet needs a 2-dimensional matrix, apply Flatten and export it as a .xlsx file (.csv also works):

data = Flatten[#, 1] &@
Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}]

Export["D:\\data0.xlsx", data]


Open in Excel, select the data from the upper left-hand side to the other corner (direction of your selection is important for Tecplot add-in): In Tecplot, change plot option from XY Line to 2D Cartesian, enable Vector: A dialog will pop up, choose x3 for U and x4 for V: Now you have your plot in Tecplot (because of the Table all the vectors sit on a grid): If you want to have more vectors, increase Table step size for variables:

data = Flatten[#, 1] &@
Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3, .1}, {y, -3,
3, .1}] If you want the same vectors you got in Mathematica:

eq[x_, y_] := {-1 - x^2 + y, 1 + x - y^2};
plt = StreamPlot[eq[x, y], {x, -3, 3}, {y, -3, 3}]


Output: Extract vectors from plt and apply eq:

data = Join[#, eq @@ #] & /@
Cases[plt, Arrow[{x_, __}] -> x, Infinity]


Result: ## StreamPlot - Without Excel

You could export the data directly from Mathematica to a format which is known to Tecplot like .dat or .plt:

### With .dat Format

Export data table to a .dat file:

Export["D:\\data1.dat",
Flatten[#, 1] &@
Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}], "PLT"]


Open Teplot, go to File > Load Data..., choose D:\\data1.dat, in Choose Loader dialog, choose Tecplot Data Loader: Change plot option from XY Line to 2D Cartesian, enable Vector. For the dialog, choose v3 variable for U and v4 for V:

### With .plt Format

First, you need to define .plt export format for Mathematica:

ImportExportRegisterExport["PLT", MyExportFormatExporter ]
MyExportFormatExporter[filename_, data_, opts___] :=
Module[{edata, strm},
edata =
"TITLE=\"Mathematica\"\nVARIABLES=" <>
StringReplace[
ExportString[
"v" <> ToString@# & /@ Range[1, #] &@Length@data[], "TSV"],
"\n" -> " "] <>
"\nZone T=\"M\"\n" <> ExportString[data, "TSV"];
strm = OpenWrite[filename];
WriteString[strm, edata];
Close[strm]
]


Now we registered PLT export format.

Export your data with PLT format:

Export["D:\\data1.plt",
Flatten[#, 1] &@
Table[{x, y, -1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}], "PLT"]


Open the file in Teplot and follow the same procedure, you will get the same result like .dat format: ## ContourPlot

We will populate points and calculate their values, export them to Excel, use Tecplot Add-in to import them to Tecplot:

ContourPlot[Cos[x] + Cos[y], {x, 0, 4 Pi}, {y, 0, 4 Pi}]


Output: Use Table and add headings:

rg1 = Range[0, 4 Pi];
rg2 = Range[0, 4 Pi];

(* Data *)
Table[Cos[x] + Cos[y], {x, rg1}, {y, rg2}]

(* Data + headings *)
addHeadings =
MapThread[Prepend, {#, Prepend[rg1, ""]}] &@Prepend[#, rg2] &;

data4 = addHeadings@Table[Cos[x] + Cos[y], {x, rg1}, {y, rg2}];


Export the data:

Export["D:\\data4.xlsx", data4]


Open in Excel, select the data from the upper left-hand side to the other corner (direction of your selection is important for Tecplot add-in): If you enable Tecplot add-in use Send to Tecplot under Add-ins Excel tab, when Tecplot opened, enable Contour: Just like StreamPlot, increasing the Table variable step size, increase the quality of the result:

rg1 = Range[0, 4 Pi, .1];
rg2 = Range[0, 4 Pi, .1]; In the end, I should mention I'm not an expert in Tecplot and you might find better solutions, and if you do, don't remember to add it to this post so it becomes helpful for future viewers.

I used Mathematica 12.2 and Tecplot 360 EX 2017 R3.

• @Bany Thank you so much for your help and for elaborating the problem in detail. It works. – Mathematicain Mar 12 at 13:49
• how can export ( .dat) file of data – Mathematicain Mar 12 at 14:49
• I edited the answer. – Ben Izd Mar 12 at 16:09
• Thank you so much. – Mathematicain Mar 12 at 16:49

Not too sure what data you want, maybe this helps, it seems to give you the data for each vector field:

Table[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}]
Export["file.xls", %]

out: {{{-13, -11}, {-12, -6}, {-11, -3},...}}


Can be used to produce the same graph... ish:

StreamPlot[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}, PlotLegends -> Automatic] d0 = Table[{-1 - x^2 + y, 1 + x - y^2}, {x, -3, 3}, {y, -3, 3}]

Export["file.txt", d0, "Table"]

ListVectorPlot[d0, StreamPoints -> 100]
` If you want the data from a graph with unknown equation / origin, maybe check this out:

How to Extract data points from plot in mathematica to redraw it with another program?

• It's not working because when I export data the I can't plot it again in Mathematica or others like excel, Tecplot. – Mathematicain Mar 7 at 18:11
• you can see the type of data that I export from comsol code. Please see this drive.google.com/file/d/1kHwbmb_E237BpN7xGuUpONnoJVWqGAFr/… – Mathematicain Mar 7 at 18:13
• @Mathematicain I'm unfamilair with Tecplot, you want to export from mathematica in a similar format to the data in the link? Or you want to Import this data? – Teabelly Mar 7 at 18:33
• The {x,y} are the first two columns of the main table (corresponding to d0), can you not just identify this in Tecplot? – Teabelly Mar 7 at 18:35
• Yes I want to export data like the data I mention. in txt of xls format – Mathematicain Mar 7 at 18:36