I'm trying to fill an area under a curve drew with pgfplots. I've tried the solution outlined in this answer:
\documentclass{article}
\usepackage{amsmath}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{pgfplots}
\colorlet{shadecolor}{gray!10}
\numberwithin{equation}{section}
\pgfplotsset{%
compat=1.11,
standard/.style={%
clip=false,
mark=none,
smooth,
axis x line*=bottom,
axis y line=left,
axis x line=middle,
axis y line=middle,
enlarge x limits=0.15,
enlarge y limits=0.15,
every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
every axis y label/.style={at={(current axis.above origin)},anchor=north east}
}
}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{figure}[!h]
\centering
\begin{tikzpicture}
\newcommand\gaussian{1.0298076 * exp(-(x-2)^2 / 0.48)}
\pgfplotsset{ticks=none};
\begin{axis}[standard,every axis plot post/.append style={%
domain=0:4,samples=200},
xlabel={$x$},
ylabel={$p(x)$},
enlargelimits=upper]
\addplot[name path=f,CornflowerBlue]{\gaussian};
\path[name path=axis] (axis cs:0,0) -- (axis cs:1,0); %%%% The problem
\addplot[
thick,
color=blue,
fill=blue,
fill opacity=0.05
]
fill between[
of=f and axis,
soft clip={domain=1.6:2.4}
];
\addplot[dashed] coordinates {(2.4,0) (2.4,0.737889)};
\addplot[dashed] coordinates {(1.6,0) (1.6,0.737889)};
\node at (axis cs:2.4,0.001) [below] {$\mu + \sigma$};
\node at (axis cs:1.6,0.001) [below] {$\mu - \sigma$};
\end{axis}
\end{tikzpicture}
\caption{Intervallo di confidenza}\label{fig:distib_norm}
\end{figure}
\end{document}
However, in the logs I see
Package pgf Warning: fill between skipped: the second input path is empty. on input line 55.
The offending line is therefore this one:
\path[name path=axis] (axis cs:0,0) -- (axis cs:1,0);
How can it be empty?
This is the result:
.

(axis cs:0,0)--(axis cs:5,0). If you place x axis labels at(axis cs:1.6,0.001)and(axis cs:2.4,0.001), it's clear thataxispath is to short to cut the gaussian path. – Ignasi Mar 06 '15 at 08:15axis cshad to be between0and1. Now it works! – rubik Mar 06 '15 at 08:17rel axis csruns from 0 to 1 where asaxis cstakes the actual domain dimensions (here from 0 to 4). – Mar 06 '15 at 09:44