Quantcast
Channel: Tufte style range frames for three dimensional plots - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 2

Tufte style range frames for three dimensional plots

0
0

This question is a follow up to this question, that allowed me to solve the two dimensional case.

For example this plot

sine

is created by the following code:

\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}

Similarly

pdf

is created by:

\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}

Now I would like to achieve the same range frame axis style in a three dimensional plot. My best attempt is:

\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}

which yields

sineXtimessineY

The option ticklabel shift={10pt}, does exactly the right thing for the tick mark labels. p. 286 of the pgfplots manual states:

Shifts tick labels in direction of the outer unit normal of the axis by an amount of ...

Compare the two versions of the sin(x)sin(y)-plot above, the tick mark labels in the lower plot moved away from the axis just right.

Unfortunately there is no tickmark shift option to shift the tick marks along the outer unit normal vector in the same way. And also no axis shift option to offset the axis.

In the two dimensional solution the trick was to use xshift and yshift transformation in the x axis line style to simply shift the axis and in the xtick style to shift the tick marks.

Is there a way to access the outer unit normal vector from the tickmark shift option and use a transformation to move the axis and the tickmarks in the same way as the tickmark labels?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images