我正在尝试编写一个宏来执行二次回归pgfplots
。我有
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{gnuplottex}
\usepackage{pgfkeys}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}
\usepackage{xparse}
\usepackage{xstring} % for \IfStrEq, \IfInteger
\makeatletter
% https://tex.stackexchange.com/a/50113/2066
\newcommand*{\IsInteger}[3]{%
\IfStrEq{#1}{ }{%
#3% is a blank string
}{%
\IfInteger{#1}{#2}{#3}%
}%
}%
\newcommand{\pgftognucolumnset}[2]{%
\IsInteger{\pgfkeysvalueof{#1}}{%
% pgf 0-indexes columns, while gnuplot 1-indexes columns, so we add 1 to adjust
\edef#2{\the\numexpr\pgfkeysvalueof{#1}+1\relax}%
}{%
\edef#2{(column("\pgfkeysvalueof{#1}"))}%
}%
}
\makeatletter
% \addplotquadraticregression[params for \addplot][default settings for a and b and c, also for x and y columns]{table file}
\NewDocumentCommand{\addplotquadraticregression}{ O{no markers} o m}{%
\pgfkeyssetvalue{/addplotquadraticregression/x}{0}
\pgfkeyssetvalue{/addplotquadraticregression/y}{1}
\pgfkeyssetvalue{/addplotquadraticregression/a}{1}
\pgfkeyssetvalue{/addplotquadraticregression/b}{1}
\pgfkeyssetvalue{/addplotquadraticregression/c}{1}
\pgfkeys{/addplotquadraticregression/.cd,#2}
\pgftognucolumnset{/addplotquadraticregression/x}{\@addplotquadraticregression@colx}%
\pgftognucolumnset{/addplotquadraticregression/y}{\@addplotquadraticregression@coly}%
\edef\@addplotquadraticregression@inita{\pgfkeysvalueof{/addplotquadraticregression/a}}%
\edef\@addplotquadraticregression@initb{\pgfkeysvalueof{/addplotquadraticregression/b}}%
\edef\@addplotquadraticregression@initc{\pgfkeysvalueof{/addplotquadraticregression/c}}%
\addplot [#1] gnuplot [raw gnuplot] { % allows arbitrary gnuplot commands
f(x) = a*x**2+b*x+c; % Define the function to fit
% Set reasonable starting values here
a=\@addplotquadraticregression@inita;
b=\@addplotquadraticregression@initb;
c=\@addplotquadraticregression@initc;
fit f(x) '#3' u \@addplotquadraticregression@colx:\@addplotquadraticregression@coly\space via a,b,c; % Select the file
stats '#3' u \@addplotquadraticregression@colx;
plot [x=STATS_min:STATS_max] f(x); % Specify the range to plot
set print "#3-parameters.dat"; % Open a file to save the parameters
print a, b, c; % Write the parameters to file
};
\pgfplotstableread{#3-parameters.dat}\parameters % Open the file Gnuplot wrote
\pgfplotstablegetelem{0}{0}\of\parameters \xdef\pgfplotstableregressiona{\pgfplotsretval} % Get first element, save into \pgfplotstableregressiona
\pgfplotstablegetelem{0}{1}\of\parameters \xdef\pgfplotstableregressionb{\pgfplotsretval}
\pgfplotstablegetelem{0}{2}\of\parameters \xdef\pgfplotstableregressionc{\pgfplotsretval}
}
\makeatother
\usepackage{filecontents}
\begin{document}
\begin{filecontents*}{data.txt}
param-0-univ-count param-1-n abstract-regression-quadratic-regression-cubic-real abstract-regression-quadratic-regression-cubic-sys abstract-regression-quadratic-regression-cubic-user close-abstract-regression-quadratic-regression-cubic-real close-abstract-regression-quadratic-regression-cubic-sys close-abstract-regression-quadratic-regression-cubic-user exact-regression-quadratic-regression-cubic-regression-linear-real exact-regression-quadratic-regression-cubic-regression-linear-sys exact-regression-quadratic-regression-cubic-regression-linear-user
1 0 0. 0. 0. 0. 0. 0. 0. 0. 0.
2 1 0. 0. 0. 0. 0. 0. 0. 0. 0.
4 2 0. 0. 0. 0. 0. 0. 0. 0. 0.
8 3 0.001 0. 0.001 0. 0. 0. 0. 0. 0.
16 4 0.002 0.002 0. 0.001 0.001 0. 0. 0. 0.
32 5 0.005 0. 0.004 0.003 0. 0.003 0.001 0. 0.001
64 6 0.01 0.006 0.003 0.006 0.006 0. 0.003 0. 0.003
128 7 0.068 0.004 0.063 0.06 0.004 0.056 0.007 0. 0.007
256 8 0.036 0. 0.036 0.026 0. 0.026 0.009 0. 0.009
512 9 0.104 0. 0.104 0.084 0. 0.084 0.019 0. 0.019
1024 10 0.262 0.003 0.258 0.221 0.003 0.217 0.04 0. 0.04
2048 11 0.798 0.003 0.794 0.692 0.003 0.688 0.105 0. 0.105
4096 12 2.39 0.003 2.386 2.179 0. 2.179 0.211 0.003 0.207
8192 13 8.301 0.016 8.285 7.866 0.012 7.853 0.434 0.003 0.43
16384 14 54.838 0.031 54.805 53.947 0.015 53.93 0.89 0.015 0.875
\end{filecontents*}
\begin{figure*}
\begin{tikzpicture}
\begin{axis}[xlabel=0-univ-count,
ylabel=time (s),
legend pos=outer north east,
width=0.95\textwidth,
axis lines=left,
xmin=0,
ymin=0,
scaled x ticks=false,
scaled y ticks=false]
\addplot[only marks,mark=o,color=red] table[x=param-0-univ-count,y=abstract-regression-quadratic-regression-cubic-real]{data.txt};
\addlegendentry{abstract-real}
\addplotquadraticregression[no markers, mark=o, color=red][x=param-0-univ-count,y=abstract-regression-quadratic-regression-cubic-real]{data.txt};
\addlegendentry{$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x^2 v\pgfmathprintnumber[print sign]{\pgfplotstableregressionb} \cdot x \pgfmathprintnumber[print sign]{\pgfplotstableregressionc}$}
\end{axis}
\end{tikzpicture}
\end{figure*}
\end{document}
效果很好:
但是,如果我尝试使用宏而不是文件中的内联表,则会失败;用替换文档正文
\begin{document}
\begin{figure*}
\begin{tikzpicture}
\pgfplotstableread{
param-0-univ-count param-1-n abstract-regression-quadratic-regression-cubic-real abstract-regression-quadratic-regression-cubic-sys abstract-regression-quadratic-regression-cubic-user close-abstract-regression-quadratic-regression-cubic-real close-abstract-regression-quadratic-regression-cubic-sys close-abstract-regression-quadratic-regression-cubic-user exact-regression-quadratic-regression-cubic-regression-linear-real exact-regression-quadratic-regression-cubic-regression-linear-sys exact-regression-quadratic-regression-cubic-regression-linear-user
1 0 0. 0. 0. 0. 0. 0. 0. 0. 0.
2 1 0. 0. 0. 0. 0. 0. 0. 0. 0.
4 2 0. 0. 0. 0. 0. 0. 0. 0. 0.
8 3 0.001 0. 0.001 0. 0. 0. 0. 0. 0.
16 4 0.002 0.002 0. 0.001 0.001 0. 0. 0. 0.
32 5 0.005 0. 0.004 0.003 0. 0.003 0.001 0. 0.001
64 6 0.01 0.006 0.003 0.006 0.006 0. 0.003 0. 0.003
128 7 0.068 0.004 0.063 0.06 0.004 0.056 0.007 0. 0.007
256 8 0.036 0. 0.036 0.026 0. 0.026 0.009 0. 0.009
512 9 0.104 0. 0.104 0.084 0. 0.084 0.019 0. 0.019
1024 10 0.262 0.003 0.258 0.221 0.003 0.217 0.04 0. 0.04
2048 11 0.798 0.003 0.794 0.692 0.003 0.688 0.105 0. 0.105
4096 12 2.39 0.003 2.386 2.179 0. 2.179 0.211 0.003 0.207
8192 13 8.301 0.016 8.285 7.866 0.012 7.853 0.434 0.003 0.43
16384 14 54.838 0.031 54.805 53.947 0.015 53.93 0.89 0.015 0.875
}{\testdata}
\begin{axis}[xlabel=0-univ-count,
ylabel=time (s),
legend pos=outer north east,
width=0.95\textwidth,
axis lines=left,
xmin=0,
ymin=0,
scaled x ticks=false,
scaled y ticks=false]
\addplot[only marks,mark=o,color=red] table[x=param-0-univ-count,y=abstract-regression-quadratic-regression-cubic-real]{\testdata};
\addlegendentry{abstract-real}
\addplotquadraticregression[no markers, mark=o, color=red][x=param-0-univ-count,y=abstract-regression-quadratic-regression-cubic-real]{\testdata};
\addlegendentry{$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x^2 \pgfmathprintnumber[print sign]{\pgfplotstableregressionb} \cdot x \pgfmathprintnumber[print sign]{\pgfplotstableregressionc}$}
\end{axis}
\end{tikzpicture}
\end{figure*}
\end{document}
导致
! Undefined control sequence.
\testdata ->\pgfpl@@
{param-0-univ-count}\pgfpl@@ {param-1-n}\pgfpl@@ {abstr...
l.97 ...uadratic-regression-cubic-real]{\testdata}
;
?
这是因为我不能仅仅使用在 gnuplot 中标识表的宏(嗯,更准确地说,我甚至不能将宏写入文件,因为它包含未定义的子宏,即pgfpl@@
)。
如果我可以将表格转换为纯文本,我可以使用 将其插入到 gnuplot 内联数据块中。但是,一旦读入表格,$Mydata << EOD ... EOD
我似乎找不到恢复原始文本的方法。例如,给我一些类似pgfplotsdata
\pgfplotstabletypeset[begin table=,end table=]{\testdata}
{ccccccccccc}%
param-0-univ-count¶m-1-n&abstract-regression-quadratic-regression-cubic-real&abstract-regression-quadratic-regression-cubic-sys&abstract-regression-quadratic-regression-cubic-user&close-abstract-regression-quadratic-regression-cubic-real&close-abstract-regression-quadratic-regression-cubic-sys&close-abstract-regression-quadratic-regression-cubic-user&exact-regression-quadratic-regression-cubic-regression-linear-real&exact-regression-quadratic-regression-cubic-regression-linear-sys&exact-regression-quadratic-regression-cubic-regression-linear-user\\%
\pgfutilensuremath {1}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}\\%
\pgfutilensuremath {2}&\pgfutilensuremath {1}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}\\%
\pgfutilensuremath {4}&\pgfutilensuremath {2}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}\\%
\pgfutilensuremath {8}&\pgfutilensuremath {3}&\pgfutilensuremath {1\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {1\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}\\%
\pgfutilensuremath {16}&\pgfutilensuremath {4}&\pgfutilensuremath {2\cdot 10^{-3}}&\pgfutilensuremath {2\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {1\cdot 10^{-3}}&\pgfutilensuremath {1\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}&\pgfutilensuremath {0}\\%
\pgfutilensuremath {32}&\pgfutilensuremath {5}&\pgfutilensuremath {5\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {4\cdot 10^{-3}}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {1\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {1\cdot 10^{-3}}\\%
\pgfutilensuremath {64}&\pgfutilensuremath {6}&\pgfutilensuremath {1\cdot 10^{-2}}&\pgfutilensuremath {6\cdot 10^{-3}}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {6\cdot 10^{-3}}&\pgfutilensuremath {6\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {3\cdot 10^{-3}}\\%
\pgfutilensuremath {128}&\pgfutilensuremath {7}&\pgfutilensuremath {6.8\cdot 10^{-2}}&\pgfutilensuremath {4\cdot 10^{-3}}&\pgfutilensuremath {6.3\cdot 10^{-2}}&\pgfutilensuremath {6\cdot 10^{-2}}&\pgfutilensuremath {4\cdot 10^{-3}}&\pgfutilensuremath {5.6\cdot 10^{-2}}&\pgfutilensuremath {7\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {7\cdot 10^{-3}}\\%
\pgfutilensuremath {256}&\pgfutilensuremath {8}&\pgfutilensuremath {3.6\cdot 10^{-2}}&\pgfutilensuremath {0}&\pgfutilensuremath {3.6\cdot 10^{-2}}&\pgfutilensuremath {2.6\cdot 10^{-2}}&\pgfutilensuremath {0}&\pgfutilensuremath {2.6\cdot 10^{-2}}&\pgfutilensuremath {9\cdot 10^{-3}}&\pgfutilensuremath {0}&\pgfutilensuremath {9\cdot 10^{-3}}\\%
\pgfutilensuremath {512}&\pgfutilensuremath {9}&\pgfutilensuremath {0.1}&\pgfutilensuremath {0}&\pgfutilensuremath {0.1}&\pgfutilensuremath {8.4\cdot 10^{-2}}&\pgfutilensuremath {0}&\pgfutilensuremath {8.4\cdot 10^{-2}}&\pgfutilensuremath {1.9\cdot 10^{-2}}&\pgfutilensuremath {0}&\pgfutilensuremath {1.9\cdot 10^{-2}}\\%
\pgfutilensuremath {1{,}024}&\pgfutilensuremath {10}&\pgfutilensuremath {0.26}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0.26}&\pgfutilensuremath {0.22}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0.22}&\pgfutilensuremath {4\cdot 10^{-2}}&\pgfutilensuremath {0}&\pgfutilensuremath {4\cdot 10^{-2}}\\%
\pgfutilensuremath {2{,}048}&\pgfutilensuremath {11}&\pgfutilensuremath {0.8}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0.79}&\pgfutilensuremath {0.69}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0.69}&\pgfutilensuremath {0.11}&\pgfutilensuremath {0}&\pgfutilensuremath {0.11}\\%
\pgfutilensuremath {4{,}096}&\pgfutilensuremath {12}&\pgfutilensuremath {2.39}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {2.39}&\pgfutilensuremath {2.18}&\pgfutilensuremath {0}&\pgfutilensuremath {2.18}&\pgfutilensuremath {0.21}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0.21}\\%
\pgfutilensuremath {8{,}192}&\pgfutilensuremath {13}&\pgfutilensuremath {8.3}&\pgfutilensuremath {1.6\cdot 10^{-2}}&\pgfutilensuremath {8.29}&\pgfutilensuremath {7.87}&\pgfutilensuremath {1.2\cdot 10^{-2}}&\pgfutilensuremath {7.85}&\pgfutilensuremath {0.43}&\pgfutilensuremath {3\cdot 10^{-3}}&\pgfutilensuremath {0.43}\\%
\pgfutilensuremath {16{,}384}&\pgfutilensuremath {14}&\pgfutilensuremath {54.84}&\pgfutilensuremath {3.1\cdot 10^{-2}}&\pgfutilensuremath {54.81}&\pgfutilensuremath {53.95}&\pgfutilensuremath {1.5\cdot 10^{-2}}&\pgfutilensuremath {53.93}&\pgfutilensuremath {0.89}&\pgfutilensuremath {1.5\cdot 10^{-2}}&\pgfutilensuremath {0.88}\\%
我如何才能将表格的原始文本恢复出来?或者我如何重新处理单元格,以 gnuplot 可以处理的格式输出它们?
答案1
verbatim
结合数字格式部分的选项手册设置一个宏来保持表格效果很好:
\makeatletter
\def\@temp@table@read#1#2\@temp@table@read@end{%
\begingroup
\def\\{^^J}%
\xdef\@temp@table{#2}%
\endgroup
}%
\pgfplotstabletypeset[begin table=\@temp@table@read,end table=\@temp@table@read@end,
set thousands separator={},
sci e,
verbatim
]{\testdata}
(我仍然愿意接受有关如何以不那么黑客的方式实现此目的的建议)
完整示例代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{gnuplottex}
\usepackage{pgfkeys}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.15}
\usepackage{xparse}
\usepackage{xstring} % for \IfStrEq, \IfInteger
\makeatletter
% https://tex.stackexchange.com/a/50113/2066
\newcommand*{\IsInteger}[3]{%
\IfStrEq{#1}{ }{%
#3% is a blank string
}{%
\IfInteger{#1}{#2}{#3}%
}%
}%
\newcommand{\pgftognucolumnset}[2]{%
\IsInteger{\pgfkeysvalueof{#1}}{%
% pgf 0-indexes columns, while gnuplot 1-indexes columns, so we add 1 to adjust
\edef#2{\the\numexpr\pgfkeysvalueof{#1}+1\relax}%
}{%
\edef#2{(column("\pgfkeysvalueof{#1}"))}%
}%
}
\makeatletter
\def\@addplotregression@table@read#1#2\@addplotregression@table@read@end{%
\begingroup
\def\\{^^J}%
\xdef\@addplotregression@table{#2}%
\StrSubstitute{\@addplotregression@table}{&}{,}[\@addplotregression@table]%
\xdef\@addplotregression@table{\@addplotregression@table}%
\endgroup
}%
% \addplotquadraticregression[params for \addplot][default settings for a and b and c, also for x and y columns]{table file}
\NewDocumentCommand{\addplotquadraticregression}{ O{no markers} o m}{%
\pgfkeyssetvalue{/addplotquadraticregression/x}{0}
\pgfkeyssetvalue{/addplotquadraticregression/y}{1}
\pgfkeyssetvalue{/addplotquadraticregression/a}{1}
\pgfkeyssetvalue{/addplotquadraticregression/b}{1}
\pgfkeyssetvalue{/addplotquadraticregression/c}{1}
\pgfkeys{/addplotquadraticregression/.cd,#2}
\pgftognucolumnset{/addplotquadraticregression/x}{\@addplotquadraticregression@colx}%
\pgftognucolumnset{/addplotquadraticregression/y}{\@addplotquadraticregression@coly}%
\edef\@addplotquadraticregression@inita{\pgfkeysvalueof{/addplotquadraticregression/a}}%
\edef\@addplotquadraticregression@initb{\pgfkeysvalueof{/addplotquadraticregression/b}}%
\edef\@addplotquadraticregression@initc{\pgfkeysvalueof{/addplotquadraticregression/c}}%
\pgfplotstabletypeset[begin table=\@addplotregression@table@read,end table=\@addplotregression@table@read@end,
set thousands separator={},
sci e,
verbatim
]{#3}%
\addplot [#1] gnuplot [raw gnuplot] { % allows arbitrary gnuplot commands
f(x) = a*x**2+b*x+c; % Define the function to fit
% Set reasonable starting values here
a=\@addplotquadraticregression@inita;
b=\@addplotquadraticregression@initb;
c=\@addplotquadraticregression@initc;
set datafile separator ",";
$Mydata << EOD^^J%
\@addplotregression@table^^J%
EOD^^J
fit f(x) $Mydata u \@addplotquadraticregression@colx:\@addplotquadraticregression@coly\space via a,b,c; % Select the file
stats $Mydata u \@addplotquadraticregression@colx;
plot [x=STATS_min:STATS_max] f(x); % Specify the range to plot
set print "parameters.dat"; % Open a file to save the parameters
print a, b, c; % Write the parameters to file
};
\pgfplotstableread{parameters.dat}\parameters % Open the file Gnuplot wrote
\pgfplotstablegetelem{0}{0}\of\parameters \xdef\pgfplotstableregressiona{\pgfplotsretval} % Get first element, save into \pgfplotstableregressiona
\pgfplotstablegetelem{0}{1}\of\parameters \xdef\pgfplotstableregressionb{\pgfplotsretval}
\pgfplotstablegetelem{0}{2}\of\parameters \xdef\pgfplotstableregressionc{\pgfplotsretval}
}
\makeatother
\usepackage{filecontents}
\begin{document}
\begin{figure*}
\begin{tikzpicture}
\pgfplotstableread{
param-0-univ-count param-1-n abstract-regression-quadratic-regression-cubic-real abstract-regression-quadratic-regression-cubic-sys abstract-regression-quadratic-regression-cubic-user close-abstract-regression-quadratic-regression-cubic-real close-abstract-regression-quadratic-regression-cubic-sys close-abstract-regression-quadratic-regression-cubic-user exact-regression-quadratic-regression-cubic-regression-linear-real exact-regression-quadratic-regression-cubic-regression-linear-sys exact-regression-quadratic-regression-cubic-regression-linear-user
1 0 0. 0. 0. 0. 0. 0. 0. 0. 0.
2 1 0. 0. 0. 0. 0. 0. 0. 0. 0.
4 2 0. 0. 0. 0. 0. 0. 0. 0. 0.
8 3 0.001 0. 0.001 0. 0. 0. 0. 0. 0.
16 4 0.002 0.002 0. 0.001 0.001 0. 0. 0. 0.
32 5 0.005 0. 0.004 0.003 0. 0.003 0.001 0. 0.001
64 6 0.01 0.006 0.003 0.006 0.006 0. 0.003 0. 0.003
128 7 0.068 0.004 0.063 0.06 0.004 0.056 0.007 0. 0.007
256 8 0.036 0. 0.036 0.026 0. 0.026 0.009 0. 0.009
512 9 0.104 0. 0.104 0.084 0. 0.084 0.019 0. 0.019
1024 10 0.262 0.003 0.258 0.221 0.003 0.217 0.04 0. 0.04
2048 11 0.798 0.003 0.794 0.692 0.003 0.688 0.105 0. 0.105
4096 12 2.39 0.003 2.386 2.179 0. 2.179 0.211 0.003 0.207
8192 13 8.301 0.016 8.285 7.866 0.012 7.853 0.434 0.003 0.43
16384 14 54.838 0.031 54.805 53.947 0.015 53.93 0.89 0.015 0.875
}{\testdata}
\begin{axis}[xlabel=0-univ-count,
ylabel=time (s),
legend pos=outer north east,
width=0.95\textwidth,
axis lines=left,
xmin=0,
ymin=0,
scaled x ticks=false,
scaled y ticks=false]
\addplot[only marks,mark=o,color=red] table[x=param-0-univ-count,y=abstract-regression-quadratic-regression-cubic-real]{\testdata};
\addlegendentry{abstract-real}
\addplotquadraticregression[no markers, mark=o, color=red][x=param-0-univ-count,y=abstract-regression-quadratic-regression-cubic-real]{\testdata};
\addlegendentry{$\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x^2 \pgfmathprintnumber[print sign]{\pgfplotstableregressionb} \cdot x \pgfmathprintnumber[print sign]{\pgfplotstableregressionc}$}
\end{axis}
\end{tikzpicture}
\end{figure*}
\end{document}
编辑:显然\pgfplotstablesave
几乎是为了这个目的而制作的(并且它\pgfplotstabletypeset
在内部使用):
\pgfplotstablesave[col sep=comma]{#3}{\jobname-regression.table}%
\bgroup
\everyeof{\noexpand}%
\def\par{^^J}%
\obeylines
\let\do\@makeother\dospecials
\xdef\@addplotregression@table{\@@input \jobname-regression.table }%
\egroup