# How to make pgfplots obey non-rotated boundaries along the axes for a rotated graph?

I'm trying to rotate a simple Gaussian, but when I try to rotate the graph, it seems clear that pgfplots is simply cropping the graph to match the boundaries specified:

The above picture shows two graphs, one is blue and isn't rotated. This graph has the correct boundaries, x is between 0 and 5.

The other graph in orange is rotated. The graph is then cropped after rotating. I wish to reverse this order, so that I can have the shape of the blue graph, rotated like the orange graph.

\documentclass{article}
\usepackage{pgfplots}

\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}
\begin{tikzpicture}[xscale=1,>=latex,
declare function={
normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));
}
]
\begin{axis}[
axis lines=none,
samples=30,
xmin=0,xmax=5,
domain=-5:5,
area plot/.style={
fill opacity=0.75,
draw=none,
fill=orange,
mark=none,
smooth
}
]
\end{axis}
\end{tikzpicture}

\end{document}


A tikzpicture is still a tikzpicture. So you can apply transformations to it.

\documentclass{article}
\usepackage{pgfplots}
\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}
\begin{tikzpicture}[>=latex,rotate around={50:(0,0)},% <-- Here
declare function={normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));}
]
\begin{axis}[
axis lines=none,
samples=30,
xmin=0,xmax=5,
domain=-5:5,
area plot/.style={
fill opacity=0.75,
draw=none,
fill=orange,
mark=none,
smooth
}
]
\end{axis}
\end{tikzpicture}
\end{document}


• For some reason I really like this! – 1010011010 Nov 6 '14 at 11:57

I don't know the relationship between TiKZ's plot coordinates and pgfplots so the results are not the same. But you don't need to use pgfplots to draw something like your example, just a fill with plot is enough and don't have to worry with clipped areas.

\documentclass[border=3mm,tikz]{standalone}

\begin{document}
\begin{tikzpicture}[declare function={%
gauss(\x)=1/(sqrt(2*pi))*exp(-(\x)^2/2);},]

\fill[color=orange, fill opacity=.75] (0,0) --plot[ domain=0:5] (\x,{gauss(\x)}) -- cycle;

\fill[color=blue, fill opacity=.75,yshift=5mm, xshift=5mm, rotate=25 ] (0,0) -- plot[ domain=0:5] (\x,{gauss(\x)}) -- cycle;

\fill[color=red, fill opacity=.75,yshift=5, xshift=5mm, rotate=50] (0,0) -- plot[ domain=0:5] (\x,{gauss(\x)}) -- cycle;
\end{tikzpicture}
\end{document}


One impractical way to do this is by embedding the tikzpicture in a rotatebox, to then make that tikzpicture a node inside another tikzpicture:

\documentclass{article}
\usepackage{pgfplots}

\pgfmathdeclarefunction{gauss}{2}{%
\pgfmathparse{1/(#2*sqrt(2*pi))*exp(-((x-#1)^2)/(2*#2^2))}%
}

\begin{document}
\begin{tikzpicture}

\node at (0,0){\rotatebox{45}{\begin{tikzpicture}[xscale=1,>=latex,
declare function={
normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));
}
]
\begin{axis}[
axis lines=none,
samples=30,
xmin=0,xmax=5,
domain=-5:5,
area plot/.style={
fill opacity=0.75,
draw=none,
fill=orange,
mark=none,
smooth
}
]