用于三维图的 Tufte 风格范围框架

用于三维图的 Tufte 风格范围框架

这个问题是这个问题,这让我能够解决二维情况。

例如这个情节

正弦

由以下代码创建:

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\def\axisdefaultwidth{360pt}
\pgfkeys{/pgfplots/x axis shift down/.style={
  x axis line style={yshift=-#1},
  xtick style={yshift=-#1},
  xticklabel shift={#1}}}
\pgfkeys{/pgfplots/y axis shift left/.style={
  y axis line style={xshift=-#1},
  ytick style={xshift=-#1},
  yticklabel shift={#1}}}

\pgfplotsset{
  every axis/.append style={thick},tick style={thick,black},
  range frame/.style={
    tick align=outside,
    scaled ticks=false,
    axis lines*=left,
    enlargelimits=false,
    x axis shift down=10pt,
    y axis shift left=10pt,
    line cap=round,
    clip=false,
    after end axis/.code={
       \draw (xticklabel* cs:0,10pt) -- ++(0,-\pgfkeysvalueof{/pgfplots/major tick length});
       \draw (xticklabel* cs:1,10pt) -- ++(0,-\pgfkeysvalueof{/pgfplots/major tick length});
       \draw (yticklabel* cs:0,10pt) -- ++(-\pgfkeysvalueof{/pgfplots/major tick length},0);
       \draw (yticklabel* cs:1,10pt) -- ++(-\pgfkeysvalueof{/pgfplots/major tick length},0);
    }
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[range frame,xtick={0,90,180,270,360}]
    \addplot[domain=0:360,samples=201] {sin(x)};
  \end{axis}
\end{tikzpicture}
\end{document}

相似地

pdf

由以下人员创建:

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\def\axisdefaultwidth{360pt}
\pgfkeys{/pgfplots/x axis shift down/.style={
  x axis line style={yshift=-#1},
  xtick style={yshift=-#1},
  xticklabel shift={#1}}}
\pgfkeys{/pgfplots/y axis shift left/.style={
  y axis line style={xshift=-#1},
  ytick style={xshift=-#1},
  yticklabel shift={#1}}}

\pgfplotsset{
  every axis/.append style={thick},tick style={thick,black},
  range frame/.style={
    tick align=outside,
    scaled ticks=false,
    axis lines*=left,
    enlargelimits=false,
    x axis shift down=10pt,
    y axis shift left=10pt,
    line cap=round,
    clip=false,
    after end axis/.code={
       \draw (xticklabel* cs:0,10pt) -- ++(0,-\pgfkeysvalueof{/pgfplots/major tick length});
       \draw (xticklabel* cs:1,10pt) -- ++(0,-\pgfkeysvalueof{/pgfplots/major tick length});
       \draw (yticklabel* cs:0,10pt) -- ++(-\pgfkeysvalueof{/pgfplots/major tick length},0);
       \draw (yticklabel* cs:1,10pt) -- ++(-\pgfkeysvalueof{/pgfplots/major tick length},0);
    }
  }
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[range frame,ytick={0},extra y ticks={0.398942},extra y tick labels={$\frac{1}{\sqrt{2π}}$},xtick=\empty,extra x ticks={-3,-2,-1,1,2,3},extra x tick labels={$-3σ$,$-2σ$,$-σ$,$σ$,$2σ$,$3σ$}]
    \addplot[domain=-5:5,samples=201,name path=A] {exp(-x^2/2)/sqrt(2*pi)};
    \path[name path=B] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0);
    \addplot[black!30] fill between[of=A and B,soft clip={(axis cs:-3,0) rectangle (axis cs:3,1)}];
    \addplot[black!20] fill between[of=A and B,soft clip={(axis cs:-2,0) rectangle (axis cs:2,1)}];
    \addplot[black!10] fill between[of=A and B,soft clip={(axis cs:-1,0) rectangle (axis cs:1,1)}];
  \end{axis}
\end{tikzpicture}
\end{document}

现在我想在三维图中实现相同的范围框架轴样式。我最好的尝试是:

\documentclass{minimal}
\usepackage{tikz}
\usepackage{pgfplots}
\def\axisdefaultwidth{360pt}
\pgfplotsset{
  every axis/.append style={thick},tick style={thick,black},
  range3frame/.style={
    tick align=outside,
    scaled ticks=false,
    enlargelimits=false,
    ticklabel shift={10pt},
    axis lines*=left,
    line cap=round,
    clip=false
  }
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[view={55}{45}]
    \addplot3[mesh,samples=41,domain=0:360] {sin(x)*sin(y)};
  \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
  \begin{axis}[range3frame,view={55}{45}]
    \addplot3[mesh,samples=41,domain=0:360] {sin(x)*sin(y)};
  \end{axis}
\end{tikzpicture}
\end{document}

得出

正弦X乘以正弦Y

选项ticklabel shift={10pt}, 对刻度标记标签的作用完全正确。pgfplots 手册第 286 页指出:

将刻度标签沿轴的外部单位法线方向移动一定量...

比较上面的两个版本的 sin(x)sin(y) 图,下图中的刻度标记标签恰好从轴移开。

不幸的是,没有tickmark shift选项可以以同样的方式沿外部单位法线向量移动刻度标记。也没有axis shift选项可以偏移轴。

在二维解决方案中,诀窍是使用xshiftyshift变换来x axis line style简单地移动轴,并使用来xtick style移动刻度标记。

有没有办法从选项中访问外部单位法线向量tickmark shift,并使用变换以与刻度标签相同的方式移动轴和刻度标记?

答案1

编辑

最新版本pgfplots附带了axis line shift,它允许我们简化样式,如下所示:

\documentclass{standalone}
\usepackage{pgfplots}
\def\axisdefaultwidth{360pt}

\pgfplotsset{
  every axis/.append style={thick},tick style={thick,black},
  %
  range3frame/.style={
    tick align=outside,
    scaled ticks=false,
    enlargelimits=false,
    axis lines*=left,
    line cap=round,
    clip=false,
    axis line shift=10pt,
  }
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[range3frame,view={55}{45}]
    \addplot3[mesh,samples=41,domain=0:360] {sin(x)*sin(y)};
  \end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

編輯結束


没有这样的预定义样式。

但是这里有一个用 5 行定义的内容:

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\def\axisdefaultwidth{360pt}

\pgfplotsset{
  every axis/.append style={thick},tick style={thick,black},
  %
  % #1 = x, y, or z
  % #2 = the shift value
  /tikz/normal shift/.code 2 args={%
    \pgftransformshift{%
        \pgfpointscale{#2}{\pgfplotspointouternormalvectorofticklabelaxis{#1}}%
    }%
  },%
  %
  range3frame/.style={
    tick align=outside,
    scaled ticks=false,
    enlargelimits=false,
    ticklabel shift={10pt},
    axis lines*=left,
    line cap=round,
    clip=false,
    xtick style={normal shift={x}{10pt}},
    ytick style={normal shift={y}{10pt}},
    ztick style={normal shift={z}{10pt}},
    x axis line style={normal shift={x}{10pt}},
    y axis line style={normal shift={y}{10pt}},
    z axis line style={normal shift={z}{10pt}},
  }
}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[range3frame,view={55}{45}]
    \addplot3[mesh,samples=41,domain=0:360] {sin(x)*sin(y)};
  \end{axis}
\end{tikzpicture}
\end{document}

该命令\pgfplotspointouternormalvectorofticklabelaxis{x}是 的快捷方式。我担心参考手册中缺少 的\pgfplotspointouternormalvectorofaxis{\pgfplotsticklabelaxisspec{x}}文档。\pgfplotspointouternormalvectorofticklabelaxis

请注意,此移位与网格线不兼容(按构造!)。要查看此情况,请尝试添加grid=major,您将看到描述略有偏差。您可能需要确定这是否是您想要的(或如何修复它)。

相关内容