Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

General purpose

My intension is to use data created by Mathematica as in

but with a nicer $\LaTeX$ conform font style and similar stuff. This is the reason why I am using the $\LaTeX$ package pgfplots. This package also allows me to add further information and fancy graphical stuff (by using TikZ) to the plot at later time.

Issue

Now I do not get Mathematica to write me a data-file which can be read by the $\LaTeX$ package pgfplots. The current data (and export) has the following structure:

DataTable = {{9/50, 5.00251*10^9, 3.02252*10^9, 2.17472*10^9, 1.97472*10^9},<<1000>>};
Export["Energy.csv", DataTable];

The idea is to plot in the end something like

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[%
        xlabel={xlabel},
        ylabel={ylabel}]
    \addplot[color=blue,mark=none] 
        table [x expr=\thisrowno{0}, y expr=\thisrowno{1}, col sep=space] {data.dat};
    \addplot[color=blue,mark=none] 
        table [x expr=\thisrowno{0}, y expr=\thisrowno{2}, col sep=space] {data.dat};
    \end{axis}
    \end{tikzpicture}
    \end{document}

EDIT:

The $\LaTeX$ routine pgfplots uses the following data structure (where the option col sep=space|tab|comma|colon|semicolon|braces|&|ampersand defines the separation character - same is also vaid for the column separation row sep=newline|\\):

Field,Energy1,    Energy2,    Energy3,    Energy4
9/50, 5.00251e+09,3.02252e+09,2.17472e+09,1.97472e+09
... (all data like this first row of data)

You might want to check out chapter 4.3.2 (Reading Coordinates From Tables) in the pgfplots manual which contains all important informations. By the way the header is not necessary but helps other readers to understand your data.

share|improve this question
2  
So, what structure would be required for this to be possible, for those of us without a familiarity/working installation of $\LaTeX$? –  Oleksandr R. Jan 4 at 0:12
1  
The "CSV" export of Mathematica creates exactly the structure you like, where one line is exported as 9/50,5.00251e9,3.02252e9,2.17472e9,1.97472e9. In you pgfplots code, you used data.dat which should be data.csv with your current approach. What exactly is the issue? –  halirutan Jan 4 at 13:37
    
@halirutan: It was a stupid error that occured because I did not choose the correct file (I still used the data.dat file. You are completely right. +1 I will rephrase an answer out of my question for other interested people (as I invested too much time in that issue). –  strpeter Jan 4 at 16:46
1  
@strpeter No problem. This happens to everyone once in a while. The good thing is, that it works now. –  halirutan Jan 4 at 16:47
add comment

1 Answer 1

Mathematica export

Just export the data such that in one column you have the x-coordinates and in another you have the y-coordinates.

DataTable = {{9/50, 5.00251*10^9, 3.02252*10^9, 2.17472*10^9, 1.97472*10^9},<<1000>>};
DataTableWithHeader = Flatten[{{{"ColumnX", "ColumnY1", "ColumnY2", "ColumnY3", "ColumnY4"}}, DataTable}, 1];
Export["Energy.csv", DataTableWithHeader];

$\LaTeX$ import and compiling

You now can use a compiler like pdflatex to create your plots from a $\LaTeX$-file like the folowing - like you desire.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[%
        xlabel={xlabel},
        ylabel={ylabel}]
    \addplot[color=blue,mark=none] 
        table [x expr=\thisrowno{0},y expr=\thisrowno{1},col sep=comma]{Energy.csv};
    \addplot[color=blue,mark=none] 
        table [x expr=\thisrowno{0},y expr=\thisrowno{2},col sep=comma]{Energy.csv};
    \end{axis}
    \end{tikzpicture}
    \end{document}

The resulting images might look like the following example.

Illustration created with pgfplots

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.