Mis datos realmente no son claramente visibles, como en: no se pueden ver bigotes de error para 50x150-k1
ni 50x150-k1
. Esto se debe (obviamente) a que estos valores son realmente pequeños, en comparación con 40x150-k
. Pensé que podría hacer que el eje x fuera logarítmico (como en el ejemplo siguiente), pero esto no ayudó mucho. Espero que los indicadores de error 50x150-k2
sean (visiblemente) casi tan grandes como 16x75-s
, ya que tienen un valor kdelta similar.
Los bigotes vienen dados por k-1 y k+1 según la tabla, siendo kdelta k+1 / k-1.
Mi código que produce el gráfico en la imagen se ve así:
\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}
¿Qué código presentaría mejor los márgenes de error? Todavía espero que log10 sea el correcto.
Código completo y datos:
\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}
En datos.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\%
Respuesta1
Supongo que estás buscando
x error plus=uci,x error minus=lci
para ponerse en marcha
\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}
Observe que me concentré en el punto principal y agregué dos $
para compilar el código. Se podría ajustar aún más el código.