我将尝试解释为什么它会令人困惑,我需要在图表中放置一些误差线。有什么想法我该怎么做吗?
\begin{document}
\begin{figure}
\begin{subfigure}{0.31\textwidth}
\centering
\begin{tikzpicture}
\begin{axis}
[name=plot,
ymin=1.8,ymax=2.7,xmin=0.45,xmax=0.7
,
xlabel = $L(m)$,
ylabel = {$T^2(s^2)$},
legend pos=north west,
scatter/classes={%
a={mark=o,draw=black}}]
\addplot[scatter,only marks,%
scatter src=explicit symbolic]%
table[meta=label] {
x y label
0.650 2.6 a
0.606 2.4 a
0.581 2.4 a
0.555 2.3 a
0.526 2.16 a
0.502 2 a
};\label{puntos}
]
\addplot [
color=red,
]
{x*3.7844+0.1529};\label{Func2}
\end{axis}
\node[anchor=north west, draw=black, fill=white] (legend) at (plot.north west) {\begin{tabular}{l l}
Ajuste & \ref{Func2}\\
Datos & \ref{puntos}
\end{tabular}};
\end{tikzpicture}
\caption{First subfigure} \label{fig:1a}
\end{subfigure}%
\end{figure}
答案1
好的,我想你想要一个绝对y 误差在两个方向(即正和负)的值为 0.08(而不是 0.8)。这很容易实现。
% used PGFPlots v1.17
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin=0.45,
xmax=0.7,
ymin=1.8,
ymax=2.7,
xlabel=$L (m)$,
ylabel={$T^2 (s^2)$},
legend pos=north west,
scatter/classes={%
a={mark=o,draw=black}%
},
]
\addplot [
scatter,
only marks,
scatter src=explicit symbolic,
% ---------------
% added stuff
error bars/.cd,
y dir=both,
y fixed=0.08,
% ---------------
] table [meta=label] {
x y label
0.650 2.6 a
0.606 2.4 a
0.581 2.4 a
0.555 2.3 a
0.526 2.16 a
0.502 2 a
};
\addplot [red] {x*3.7844+0.1529};
% (simplified your legend)
\legend{
Ajuste,
Datos,
}
\end{axis}
\end{tikzpicture}
\end{document}