在对数-对数图上使用椭圆作为误差线

在对数-对数图上使用椭圆作为误差线

我想绘制一个使用对数刻度的 XY 散点图。我还想绘制误差线。

标准方法是绘制水平和垂直误差线,但如果我有很多数据点,这看起来很乱。所以我想把这些点画成半透明的椭圆。这个想法是,如果椭圆完全在对角线上方(或完全在对角线下方),那么我们可以确信“我们的方法”获胜或“他们的方法”获胜,如果它与对角线重叠,那么我们就不确定了。

部分灵感来自这个答案我想到了一个几乎可行的方法,只是轴具有线性刻度。如果我将它们更改为对数刻度,它就会中断。所以我的问题是:我如何才能使它与对数轴一起工作?(我很乐意将椭圆的宽度和高度表示为相对误差或绝对误差,无论哪种更方便。)

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}

\begin{document}

\begin{tikzpicture}

\begin{axis} [
  %xmode=log, ymode=log, 
  %JW: Should be log scales but then the ellipses don't work :(
  ticklabel style={
        /pgf/number format/fixed,
        /pgf/number format/precision=2
  },
  height=85mm,
  width=85mm,
  xmin=1, xmax=1.3,
  ymin=1, ymax=1.3,
  xlabel = {Competitor's speedup factor},
  ylabel = {Our speedup factor},
]
\foreach \x/\y/\w/\h in {
  % x position / y position / width of ellipse / height of ellipse
  1.02/1.03/0.01/0.02, 
  1.04/1.05/0.02/0.01, 
  1.05/1.03/0.03/0.01,
  1.15/1.13/0.04/0.02,
  1.15/1.25/0.01/0.04
}{
  \edef\temp{\noexpand% JW: some unpleasant hackery needed here (https://tex.stackexchange.com/a/17817/25356)
  \draw[fill=black, draw=none, opacity=0.3] 
    (axis cs: \x,\y) circle [x radius=\w, y radius=\h];
  }
  \temp
} 
% JW: Plotting the y=x reference line
\draw[dotted] (rel axis cs: 0,0) -- (rel axis cs: 1,1);
\end{axis}
\end{tikzpicture}

\end{document}

上述代码的输出

答案1

很明显为什么它“不起作用”:在对数坐标中,您无法以通常的方式添加坐标,因此半径的解释与您想要的不同。但是,使用 可以轻松解决这个问题calc

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.5.1}

\begin{document}

\begin{tikzpicture}

\begin{axis} [
  xmode=log, ymode=log, 
  %JW: Should be log scales but then the ellipses don't work :(
  ticklabel style={
        /pgf/number format/fixed,
        /pgf/number format/precision=2
  },
  height=85mm,
  width=85mm,
  xmin=1, xmax=1.3,
  ymin=1, ymax=1.3,
  xlabel = {Competitor's speedup factor},
  ylabel = {Our speedup factor},
]
\foreach \x/\y/\w/\h in {
  % x position / y position / width of ellipse / height of ellipse
  1.02/1.03/0.01/0.02, 
  1.04/1.05/0.02/0.01, 
  1.05/1.03/0.03/0.01,
  1.15/1.13/0.04/0.02,
  1.15/1.25/0.01/0.04
}{
  \edef\temp{% JW: some unpleasant hackery needed here (https://tex.stackexchange.com/a/17817/25356)
  \noexpand\path[fill,fill opacity=0.3] 
  let \noexpand\p1=($(axis cs: \x+\w,\y+\h)-(axis cs: \x-\w,\y-\h)$)
  in ($(axis cs: \x+\w,\y+\h)!0.5!(axis cs: \x-\w,\y-\h)$)
  circle[x radius=\noexpand\x1/2,y radius=\noexpand\y1/2];
  }
  \temp
} 
% JW: Plotting the y=x reference line
\draw[dotted] (rel axis cs: 0,0) -- (rel axis cs: 1,1);
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

当然,在对数坐标变换下,椭圆将被映射到不同的形状。变换后的椭圆的一阶近似如下

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5.1}

\begin{document}

\begin{tikzpicture}

\begin{axis} [
  xmode=log, ymode=log, 
  %JW: Should be log scales but then the ellipses don't work :(
  ticklabel style={
        /pgf/number format/fixed,
        /pgf/number format/precision=2
  },
  height=85mm,
  width=85mm,
  xmin=1, xmax=1.3,
  ymin=1, ymax=1.3,
  xlabel = {Competitor's speedup factor},
  ylabel = {Our speedup factor},
]
\foreach \x/\y/\w/\h in {
  % x position / y position / width of ellipse / height of ellipse
  1.02/1.03/0.01/0.02, 
  1.04/1.05/0.02/0.01, 
  1.05/1.03/0.03/0.01,
  1.15/1.13/0.04/0.02,
  1.15/1.25/0.01/0.04
}{\pgfmathsetmacro{\mylooseness}{sqrt(min(\w/\h,\h/\w))}
  \edef\temp{% JW: some unpleasant hackery needed here (https://tex.stackexchange.com/a/17817/25356)
  \noexpand\path[fill,fill opacity=0.3,looseness=\mylooseness] (axis cs: \x-\w,\y) to[out=90,in=180]
  (axis cs: \x,\y+\h) to[out=0,in=90] (axis cs: \x+\w,\y)  to[out=-90,in=0]
  (axis cs: \x,\y-\h) to[out=180,in=-90] cycle;
  }
  \temp
} 
% JW: Plotting the y=x reference line
\draw[dotted] (rel axis cs: 0,0) -- (rel axis cs: 1,1);
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容