我有标准差条,但没有符号标记。如何才能显示一个?
我从中获取了统计代码TikZ:如果用于 tikzpicture,如何将特定表传递给 \pgfplotstableset
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}
\pgfplotsset{compat = 1.10}
%% Code chunk for statistics starts here...
\newcommand{\calcrowmean}{
\def\rowmean{0}
\pgfmathparse{\pgfkeysvalueof{/pgfplots/table/summary statistics/end index}-\pgfkeysvalueof{/pgfplots/table/summary statistics/start index}+1}
\edef\numberofcols{\pgfmathresult}
% ... loop over all columns, summing up the elements
\pgfplotsforeachungrouped \col in {\pgfkeysvalueof{/pgfplots/table/summary statistics/start index},...,\pgfkeysvalueof{/pgfplots/table/summary statistics/end index}}{
\pgfmathparse{\rowmean+\thisrowno{\col}/\numberofcols}
\edef\rowmean{\pgfmathresult}
}
}
\newcommand{\calcstddev}{
\def\rowstddev{0}
\calcrowmean
\pgfplotsforeachungrouped \col in {\pgfkeysvalueof{/pgfplots/table/summary statistics/start index},...,\pgfkeysvalueof{/pgfplots/table/summary statistics/end index}}{
\pgfmathparse{\rowstddev+(\thisrowno{\col}-\rowmean)^2/(\numberofcols-1)}
\edef\rowstddev{\pgfmathresult}
}
\pgfmathparse{sqrt(\rowstddev)}
}
\pgfplotstableset{
mystat/.style = {
summary statistics/start index/.initial=1,
summary statistics/end index/.initial=3,
create col/mean/.style={
/pgfplots/table/create col/assign/.code={% In each row ...
\calcrowmean
\pgfkeyslet{/pgfplots/table/create col/next content}\rowmean
}
},
create col/standard deviation/.style={
/pgfplots/table/create col/assign/.code={% In each row ...
\calcstddev
\pgfkeyslet{/pgfplots/table/create col/next content}\pgfmathresult
}
}
}
}
%% ...code chunk for statistics ends here
\begin{document}
\begin{filecontents*}{inhibdata.txt}
x rep1 rep2 rep3 rep4 rep5 rep6 rep7 rep8
-6.60206 0.4707758 0.471134 0.464 0.4738401 0.4835494 0.4763314 0.4777448 0.4634806
-6.60206 0.2826772 0.2869296 0.2830769 0.2863636 0.2739131 0.2830051 0.2679083 0.263196
\end{filecontents*}
\pgfplotstableset{
mystat,
create on use/mean/.style={create col/mean},
create on use/stddev/.style={create col/standard deviation}
}
\begin{tikzpicture}
\begin{axis}[
align = center,
xmin = -8.6,
xmax = -5,
ymin = 0.15,
ymax = 0.65,
xtick = {-8, -7, ..., -5}
]
\addplot[only marks, mark = circle, red, error bars/.cd, y dir = both,
y explicit] table[x = x, y = mean, y error = stddev]{inhibdata.txt};
\legend{$Z' = 0.757$};
\end{axis}
\end{tikzpicture}
\end{document}
我相信由于 SD 条太小所以pgfplots
不会放入符号。
答案1
我不认为mark=circle
这是有效的。但是,使用是有效的mark = o
,但不确定这在那种情况下是否有助于显示错误栏:
笔记:
- 要获得实心圆圈,请使用
mark = *
,并mark size=0.5pt
根据需要调整大小。
代码:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usepackage{filecontents}
%\pgfplotsset{compat = 1.10}
%% Code chunk for statistics starts here...
\newcommand{\calcrowmean}{
\def\rowmean{0}
\pgfmathparse{\pgfkeysvalueof{/pgfplots/table/summary statistics/end index}-\pgfkeysvalueof{/pgfplots/table/summary statistics/start index}+1}
\edef\numberofcols{\pgfmathresult}
% ... loop over all columns, summing up the elements
\pgfplotsforeachungrouped \col in {\pgfkeysvalueof{/pgfplots/table/summary statistics/start index},...,\pgfkeysvalueof{/pgfplots/table/summary statistics/end index}}{
\pgfmathparse{\rowmean+\thisrowno{\col}/\numberofcols}
\edef\rowmean{\pgfmathresult}
}
}
\newcommand{\calcstddev}{
\def\rowstddev{0}
\calcrowmean
\pgfplotsforeachungrouped \col in {\pgfkeysvalueof{/pgfplots/table/summary statistics/start index},...,\pgfkeysvalueof{/pgfplots/table/summary statistics/end index}}{
\pgfmathparse{\rowstddev+(\thisrowno{\col}-\rowmean)^2/(\numberofcols-1)}
\edef\rowstddev{\pgfmathresult}
}
\pgfmathparse{sqrt(\rowstddev)}
}
\pgfplotstableset{
mystat/.style = {
summary statistics/start index/.initial=1,
summary statistics/end index/.initial=3,
create col/mean/.style={
/pgfplots/table/create col/assign/.code={% In each row ...
\calcrowmean
\pgfkeyslet{/pgfplots/table/create col/next content}\rowmean
}
},
create col/standard deviation/.style={
/pgfplots/table/create col/assign/.code={% In each row ...
\calcstddev
\pgfkeyslet{/pgfplots/table/create col/next content}\pgfmathresult
}
}
}
}
%% ...code chunk for statistics ends here
\begin{document}
\begin{filecontents*}{inhibdata.txt}
x rep1 rep2 rep3 rep4 rep5 rep6 rep7 rep8
-6.60206 0.4707758 0.471134 0.464 0.4738401 0.4835494 0.4763314 0.4777448 0.4634806
-6.60206 0.2826772 0.2869296 0.2830769 0.2863636 0.2739131 0.2830051 0.2679083 0.263196
\end{filecontents*}
\pgfplotstableset{
mystat,
create on use/mean/.style={create col/mean},
create on use/stddev/.style={create col/standard deviation}
}
\begin{tikzpicture}
\begin{axis}[
align = center,
xmin = -8.6,
xmax = -5,
ymin = 0.15,
ymax = 0.65,
xtick = {-8, -7, ..., -5}
]
\addplot[only marks, mark = o, red, error bars/.cd, y dir = both,
y explicit] table[x = x, y = mean, y error = stddev]{inhibdata.txt};
\legend{$Z' = 0.757$};
\end{axis}
\end{tikzpicture}
\end{document}