PGFPlots 使小对数值易于呈现

PGFPlots 使小对数值易于呈现

我的数据确实不清晰可见,例如:看不到 和 的误差线50x150-k150x150-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}

在data.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}

在此处输入图片描述

请注意,我重点突出了要点,并添加了两个代码$以使代码能够编译。可以进一步调整代码。

相关内容