# How can I add another plot to the \addplot command in PGFPlots?

My goal is to add another plot to the \addplot command and this small example hopefully shows what I'm trying to do:

\documentclass{standalone}
\usepackage{pgfplotstable}
\begin{document}

procs, none
16, 6.079748e+03
32, 3.624823e+03
64, 1.685646e+03
128, 9.180763e+02
256, 5.977239e+02
512, 4.410280e+02
}\scalability

\begin{tikzpicture}
\begin{loglogaxis}[
ylabel={Time (sec)},
xtick=data,
xticklabels from table={\scalability}{procs},
table/x=procs,
set scaling/.code={
\edef\xcol{\pgfkeysvalueof{/pgfplots/table/x}}
\pgfplotstablegetelem{0}{\xcol}\of{\scalability}
\edef\proc{\pgfplotsretval}
\pgfplotstablegetelem{0}{\pgfkeysvalueof{/pgfplots/y}}\of{\scalability}
\edef\offset{\pgfplotsretval}
\pgfplotsset{table/y expr=\offset * \proc / \thisrowno{0}}
\pgfplotsextra{
\draw (1,1) -- (256,256);              % this is drawn
\addplot table[y=none] {\scalability}; % this is not
}
},
scaling/.style={
forget plot,
set scaling,
},
forget plot style={opacity=0.4},
]

\end{loglogaxis}
\end{tikzpicture}

\end{document}

What I'd like to see is:

but tinkering with the .code functionality (and also execute at end plot) nothing seems to be able to call another \addplot only lower level TikZ commands (\draw, \path, etc.):

Is there any way to get another \addplot appended?

-
I think this is going to be quite hard. It would probably be easier to define a new command that calls both of the plots. Do you have a particular reason for not wanting that? –  Jake Jun 19 '12 at 21:31
Well, for starters, the execute and .code keys seemed like the elegant way to do this. Also, if defining a \newcommand, it seemed quite hacky to pass optional key-value pairs down to pgfplots; i.e. \mynewplotcommand +[optional styles to append]; \mynewplotcommand [optional styles to override] If passing that down to pgfplots is easier than it seems, then it would indeed work. –  Sean Farley Jun 20 '12 at 0:02

Your approach does not work because \addplot is designed to be placed within the axis -- and \pgfplotsextra is designed to NOT process things inside of an axis (but to postpone their processing).

If you want to use \addplot, you have to place it into the axis.

But from what I understand from your application, I believe that you can simply place your expression evaluation stuff directly in front of the plot in question:

\documentclass{standalone}
\usepackage{pgfplotstable}
\begin{document}

procs, none
16, 6.079748e+03
32, 3.624823e+03
64, 1.685646e+03
128, 9.180763e+02
256, 5.977239e+02
512, 4.410280e+02
}\scalability

\begin{tikzpicture}
\begin{loglogaxis}[
ylabel={Time (sec)},
xtick=data,
xticklabels from table={\scalability}{procs},
table/x=procs,
table/y=none,
forget plot style={opacity=0.4},
]

\pgfplotstablegetelem{0}{\pgfkeysvalueof{/pgfplots/table/x}}\of{\scalability}
\edef\proc{\pgfplotsretval}
\pgfplotstablegetelem{0}{\pgfkeysvalueof{/pgfplots/table/y}}\of{\scalability}
\edef\offset{\pgfplotsretval}

\addplot +[forget plot] table[y expr=\offset * \proc / \thisrowno{0}] {\scalability};