# “Styles” for PGFplots table expressions

Is it possible to use a style, or something equivalent, to specify the column expressions for plot table? The objective is to be able to use the same expressions for a large number of different plots with a minimum of repetitive typing.

Here is an example (which does not compile) that suggests what I would like to be able to do:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{/pgfplots/columns/.style={x=dof,y expr={\thisrow{L2}+\thisrow{Lmax}}}}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}
\addplot table[columns] {      % sample data from PGFplots manual
dof     L2              Lmax            maxlevel
5       8.31160034e-02  1.80007647e-01  2
17      2.54685628e-02  3.75580565e-02  3
49      7.40715288e-03  1.49212716e-02  4
129     2.10192154e-03  4.23330523e-03  5
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}

-

\pgfplotsset{/pgfplots/columns/.style={x=dof,y expr={\thisrow{L2}+\thisrow{Lmax}}}}


try

\pgfplotsset{table/columns/.style={x=dof,y expr={\thisrow{L2}-\thisrow{Lmax}}}}


Also, your end of line comment % sample data from... is interfering with the line

5       8.31160034e-02  1.80007647e-01  2


being plotted.

-
I moved the comment so it doesn't interfere with the data. – David Z Jul 3 '13 at 5:42

When you use \pgfplotsset it is automatically the pgfplots key family but you need to wrap the column style in to some other key if you will selectively use it. Otherwise

\pgfplotsset{columns/.style={x=dof,y expr={\thisrow{L2}+\thisrow{Lmax}}}}


sets the style globally. And you can simply use

\addplot table {....};


without any options as the style is global. An example of selective use

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{my col style/.style={columns/.append style={x=dof,y expr={\thisrow{L2}+\thisrow{Lmax}}}}}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}
\addplot table[my col style] {      % sample data from PGFplots manual
dof     L2              Lmax            maxlevel
5       8.31160034e-02  1.80007647e-01  2
17      2.54685628e-02  3.75580565e-02  3
49      7.40715288e-03  1.49212716e-02  4
129     2.10192154e-03  4.23330523e-03  5
};
\addplot table[my col style] {      % sample data from PGFplots manual
dof     L2              Lmax            maxlevel
20       8.31160034e-02  1.80007647e-01  2
137      2.54685628e-02  3.75580565e-02  3
249      7.40715288e-03  1.49212716e-02  4
5129     2.10192154e-03  4.23330523e-03  5
};
\end{loglogaxis}
\end{tikzpicture}
\end{document}


-
I'm not clear on what this is supposed to do. The data plotted in your example are just L2, not L2+Lmax as is supposed to be the case. (Sorry for the late response; I missed the notification about your answer.) – David Z Jul 11 '13 at 15:09