我在使用 PGFplots 中的线性回归函数时遇到了问题。该包给出的方程的符号发生了变化。
\documentclass[12pt,letterpaper]{article}
\usepackage[letterpaper, margin = 1 in]{geometry}
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\pgfplotsset{width=10cm,
compat=1.3,
legend style={font=\footnotesize}}
\begin{axis}[
xlabel={$\dfrac{T_{e}-T_{a}}{I_{T}}$ [\si{\kelvin \metre\squared\per\watt}]},
ylabel={Eficiencia instantánea $[-]$},
legend cell align=left,
legend pos=north east]
\addplot[only marks] table[row sep=\\]{
X Y\\
0.0125613 0.7422\\
0.0128012 0.7384\\
0.0130288 0.7217\\
0.0132965 0.6981\\
0.0135467 0.6715\\
};
\addlegendentry{Mediciones}
\addplot[color=NavyBlue,mark=*] table[row sep=\\,
y={create col/linear regression={y=Y}}]
{
X Y\\
0.0125613 0.7422\\
0.0128012 0.7384\\
0.0130288 0.7217\\
0.0132965 0.6981\\
0.0135467 0.6715\\
};
\addlegendentry{Regresión Lineal}
\end{axis}
\end{tikzpicture}
\end{figure}
\begin{equation}
\hat{\eta_{i}}=\pgfmathprintnumber{\pgfplotstableregressiona} \pgfmathprintnumber[print sign]{\pgfplotstableregressionb}\frac{\Delta T}{I_{T}}
\end{equation}
答案1
除了你的文档没有编译之外,你还混淆了斜率和偏移量。\pgfplotstableregressiona
是斜率,\pgfplotstableregressionb
是偏移量。如果你纠正了这一点,你会得到
\documentclass[12pt,letterpaper]{article}
\usepackage[letterpaper, margin = 1 in]{geometry}
\usepackage[spanish, es-tabla]{babel}
\usepackage[utf8]{inputenc}
\usepackage{float}
\usepackage{siunitx}
\usepackage{mathtools}
\usepackage[dvipsnames,table,longtable,x11names]{xcolor}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\begin{document}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\pgfplotsset{width=10cm,
compat=1.16,
legend style={font=\footnotesize}}
\begin{axis}[
xlabel={$\dfrac{T_{e}-T_{a}}{I_{T}}$ [\si{\kelvin \metre\squared\per\watt}]},
ylabel={Eficiencia instant\'anea $[-]$},
legend cell align=left,
legend pos=north east]
\addplot[only marks] table[row sep=\\]{
X Y\\
0.0125613 0.7422\\
0.0128012 0.7384\\
0.0130288 0.7217\\
0.0132965 0.6981\\
0.0135467 0.6715\\
};
\addlegendentry{Mediciones}
\addplot[color=NavyBlue,mark=*] table[row sep=\\,
y={create col/linear regression={y=Y}}]
{
X Y\\
0.0125613 0.7422\\
0.0128012 0.7384\\
0.0130288 0.7217\\
0.0132965 0.6981\\
0.0135467 0.6715\\
};
\addlegendentry{Regresi\'on Lineal}
\end{axis}
\end{tikzpicture}
\end{figure}
\begin{equation}
\hat{\eta_{i}}=\pgfmathprintnumber{\pgfplotstableregressionb}
\pgfmathprintnumber[print sign]{\pgfplotstableregressiona}\frac{\Delta T}{I_{T}}
\end{equation}
\end{document}