我的數據確實不清晰可見,如: no error shakers can be see 50x150-k1
fornor 50x150-k1
。 (顯然)這是因為與 相比,這些值非常小40x150-k
。我以為我可以將 x 軸設為對數(如下例所示),但這並沒有太大幫助。我預期誤差線50x150-k2
(明顯) 幾乎與 一樣大16x75-s
,因為它們具有相似的 kdelta 值。
根據表,晶須由 k-1 和 k+1 給出,kdelta 為 k+1 / k-1。
我生成圖像中的圖形的程式碼如下所示:
\pgfplotstableread{data.txt}\data
\pgfplotstableset{create on use/error/.style={
create col/expr={\thisrow{uci}-\thisrow{mean}}
}
}
\begin{tikzpicture}[trim axis left,trim axis right]
\begin{axis}[y=-\baselineskip,
scale only axis,
width = 7cm,
enlarge y limits = {abs=0.5},
axis y line* = middle,
y axis line style = dashed,
ytick = \empty,
axis x line* = bottom,
xmode=log,
]
\addplot+[only marks][error bars/.cd,x dir=both, x explicit]
table [x=mean,y expr=\coordindex,x error=error]{\data};
\end{axis}
\end{tikzpicture}
什麼程式碼可以更好地呈現誤差範圍?我仍然期望 log10 是正確的。
完整程式碼和數據:
\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[swedish]{babel}
\usepackage{stix} % font
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{siunitx}
\sisetup{
output-exponent-marker = \ensuremath{\mathrm{e}},
exponent-product={},
retain-explicit-plus
}
% Read data file, create new column ``upper CI boundary - mean''
\pgfplotstableread{data.txt}\data
\pgfplotstableset{create on use/error/.style={
create col/expr={\thisrow{uci}-\thisrow{mean}}
}
}
% Define the command for the plot
\newcommand{\errplot}{%
\begin{tikzpicture}[trim axis left,trim axis right]
\begin{axis}[y=-\baselineskip,
scale only axis,
width = 7cm,
enlarge y limits = {abs=0.5},
axis y line* = middle,
y axis line style = dashed,
ytick = \empty,
axis x line* = bottom,
xmode=log,
]
% ``mean'' must be present in the datafile,
%``error'' is the newly generated column
\addplot+[only marks][error bars/.cd,x dir=both, x explicit]
table [x=mean,y expr=\coordindex,x error=error]{\data};
\end{axis}
\end{tikzpicture}%
}
\begin{document}
% Get number of rows in datafile
\pgfplotstablegetrowsof{\data}
\let\numberofrows=\pgfplotsretval
% Print the table
\pgfplotstabletypeset[columns={name,error,mean,lci, uci, frac},
% Booktabs rules
every head row/.style={
before row={%
\toprule
& \textbf{Felmarginaler} $\log_{10}$& & \multicolumn{3}{c}{\textbf{Värden för \mu_i \pm 1\%}} \\
\cmidrule(lr){4-6}
},
after row={ \midrule},
},
every last row/.style = {after row=[3ex]\bottomrule},
% Set header name
columns/name/.style = {string type, column name=\textbf{ID}},
% Use the ``error'' column to call the \errplot command in a multirow cell
% in the first row, keep empty for all other rows
columns/error/.style = {
column name = {},
assign cell content/.code = {% use \multirow for Z column:
\ifnum\pgfplotstablerow=0
\pgfkeyssetvalue{/pgfplots/table/@cell content}
{\multirow{\numberofrows}{6.5cm}{\errplot}}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
\fi
}
},
columns/mean/.style = {
column name = $k$,
string type,
column type={S},
},
columns/lci/.style = {
column name = $k_{-1}$,
string type,
column type={c},
},
columns/uci/.style = {
column name = $k_{+1}$,
string type,
column type={c},
},
columns/frac/.style = {
column name = $k_{\Delta}$,
string type,
},
]{\data}
\end{document}
在數據.txt中:
name mean lci uci frac
16x75-s-k 1.18e-3 9.85e-4 1.50e-3 152\%
40x150-k 3.07e-4 1.76e-4 4.37e-4 248\%
50x150-k$_{1}$ 6.45e-4 5.76e-4 6.50e-4 112\%
50x150-k$_{2}$ 5.94e-5 4.71e-5 6.00e-5 127\%
答案1
我猜你正在尋找
x error plus=uci,x error minus=lci
開始吧
\documentclass[border=10pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[swedish]{babel}
\usepackage{stix} % font
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{amsmath}
\usepackage{siunitx}
\sisetup{
output-exponent-marker = \ensuremath{\mathrm{e}},
exponent-product={},
retain-explicit-plus
}
% Read data file, create new column ``upper CI boundary - mean''
\pgfplotstableread{data.txt}\data
\pgfplotstableset{create on use/error/.style={
create col/expr={\thisrow{uci}-\thisrow{mean}}
}
}
% Define the command for the plot
\newcommand{\errplot}{%
\begin{tikzpicture}[trim axis left,trim axis right]
\begin{axis}[y=-\baselineskip,
scale only axis,
width = 7cm,
enlarge y limits = {abs=0.5},
axis y line* = middle,
y axis line style = dashed,
ytick = \empty,
axis x line* = bottom,
xmode=log,
]
% ``mean'' must be present in the datafile,
%``error'' is the newly generated column
\addplot+[only marks][error bars/.cd,x dir=both, x explicit]
table [x=mean,y expr=\coordindex,
x error plus=uci,x error minus=lci]{\data};
\end{axis}
\end{tikzpicture}%
}
\begin{document}
% Get number of rows in datafile
\pgfplotstablegetrowsof{\data}
\let\numberofrows=\pgfplotsretval
% Print the table
\pgfplotstabletypeset[columns={name,error,mean,lci, uci, frac},
% Booktabs rules
every head row/.style={
before row={%
\toprule
& \textbf{Felmarginaler} $\log_{10}$& &
\multicolumn{3}{c}{\textbf{V\"arden f\"or $\mu_i \pm 1\%$}} \\
\cmidrule(lr){4-6}
},
after row={ \midrule},
},
every last row/.style = {after row=[3ex]\bottomrule},
% Set header name
columns/name/.style = {string type, column name=\textbf{ID}},
% Use the ``error'' column to call the \errplot command in a multirow cell
% in the first row, keep empty for all other rows
columns/error/.style = {
column name = {},
assign cell content/.code = {% use \multirow for Z column:
\ifnum\pgfplotstablerow=0
\pgfkeyssetvalue{/pgfplots/table/@cell content}
{\multirow{\numberofrows}{6.5cm}{\errplot}}%
\else
\pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
\fi
}
},
columns/mean/.style = {
column name = $k$,
string type,
column type={S},
},
columns/lci/.style = {
column name = $k_{-1}$,
string type,
column type={c},
},
columns/uci/.style = {
column name = $k_{+1}$,
string type,
column type={c},
},
columns/frac/.style = {
column name = $k_{\Delta}$,
string type,
},
]{\data}
\end{document}
請注意,我專注於要點並添加了兩個$
以使程式碼編譯。人們可以進一步調整程式碼。