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

Is there anyway to reuse the data of a \addplot table for plotting in another axis environment?

I would like to avoid putting the data into a separate file. Is there any way to refer to the data in a table for plotting?

Something like: (It cannot compile)

\documentclass[12pt]{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round
]
\addplot [color=white!70!black,solid,line width=0.5pt,forget plot]
  table[name=tab1,row sep=crcr]{
1   -1  \\
2   -2  \\
3   3   \\
4   4   \\
};
\end{axis}

\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round
]
\addplot [color=red,solid,line width=0.8pt,forget plot]
table[name=tab1]{tab1};

\end{axis}
\end{tikzpicture}%

\end{document}
share|improve this question

1 Answer 1

up vote 4 down vote accepted

You can use pgfplotstable facilities to read and hold it in a macro

\documentclass[12pt]{article}
\usepackage{pgfplotstable}%<== Loads pgfplots anyway
\pgfplotsset{compat=1.10}
\pgfplotstableread[row sep=crcr]{
1   -1  \\
2   -2  \\
3   3   \\
4   4   \\
}\mytable

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round
]
\addplot [color=black!30,solid,line width=1pt,forget plot]
  table {\mytable};
\end{axis}

\begin{axis}[%
width=5cm,
height=5cm,
scale only axis,
enlargelimits=false,
line join=round,at={(7cm,0)}
]
\addplot [color=red,solid,line width=0.5pt,forget plot]
table {\mytable};

\end{axis}
\end{tikzpicture}%

\end{document}

enter image description here

share|improve this answer

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.