3

I have a tabular environment which has two columns representing x and y data. Is there a way for pgfplots to reference the data in that tabular and plot it?

Example table:

\begin{tabular}{ll}
 1 & 3.4 \\
 2 & 6.7 \\
 3 & 8.9 \\
 4 & 12.4 \\
 5 & 7.8
 \end{tabular}

Current method of using pgfplot:

\addplot coordinates {
( 1, 3.4 )
( 2, 6.7 )
( 3, 8.9 )
( 4, 12.4 )
( 5, 7.8 )
};

Is there a way for pgfplot to reference the data in the tabular environment instead of repeating the data in the addplot (without using externals files if possible).

4

You can go the other way as you can read your data and either use it in tabular code or in plotting

\documentclass{article}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}


\begin{document}
\pgfplotstableread[col sep=ampersand,row sep=\\,header=false]{
 1 & 3.4 \\
 2 & 6.7 \\
 3 & 8.9 \\
 4 & 12.4 \\
 5 & 7.8 \\
}\mytable

\pgfplotstabletypeset[column type=l,every head row/.style={output empty row}]{\mytable}

\begin{tikzpicture}
\begin{axis}
\addplot table{\mytable};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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.