How can use pgfplots to fill below for a semilogy axis?

I am plotting my y axis on a log scale, and many of the y values are less then one.

Using the following code:

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{pgfplots} % drawing plots right here in this file!
\pgfplotsset{compat=1.9} % latest stable release

\begin{document}

\pagestyle{empty}

\begin{tikzpicture}
\begin{loglogaxis}
\end{loglogaxis}
\end{tikzpicture}

\end{document}


Clearly the cycle is starting at "log(y) = 0", so some values are filled above the function and some below.

How can I get it to plot below the function for all values of y, and get the fill to go to the minimum value on the y axis?

-

Use the log origin=infty key for the loglogaxis. This sets "zero" on the axis to negative infinity. For the sake of completeness, I should note that your description and the MWE you provided are inconsistent (semilog vs. loglog, plots, etc.). I answered based on the MWE, but it should be adaptable to whatever your actual use case is.

Code

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{pgfplots} % drawing plots right here in this file!
\pgfplotsset{compat=1.9} % latest stable release

\begin{document}

\pagestyle{empty}

\begin{tikzpicture}
\begin{loglogaxis}[log origin=infty] % <<< added key here
\end{loglogaxis}
\end{tikzpicture}

\end{document}


Alternative Solution using fillbetween:

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{pgfplots} % drawing plots right here in this file!
\pgfplotsset{compat=1.9} % latest stable release
\usepgfplotslibrary{fillbetween}

\begin{document}

\pagestyle{empty}

\begin{tikzpicture}
\begin{loglogaxis}
\addplot[domain=0.3:7,name path=B,update limits=false] {0.05}; % this must be below the axis limit
\addplot[black] fill between[of=A and B]; % fill between paths A and B
\end{loglogaxis}
\end{tikzpicture}

\end{document}


Output

(Same as above, but with tick marks on top of the fill.)

-

Use of clip skill. It seems that the code and the image are of different coordinate systems -- loglog and semilog. So this solution provides two results, depending on the coordinate system. The key notion is to setup a clip rectangle, followed by the closed curve with x axis. The intersection of these two areas formed by the two commands would be the desired result.

Code

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{pgfplots} % drawing plots right here in this file!
\pgfplotsset{compat=1.8} % latest stable release

\begin{document}

\pagestyle{empty}

\begin{tikzpicture}
\begin{loglogaxis}
\begin{scope}
\clip (axis cs: 0.1,0.1) rectangle (axis cs:10,10);
\addplot+[mark=none,domain=0.1:10,fill=blue!20!white] {x} -- (axis cs: 0.1,0.1) --(axis cs: 10,0.1) --(axis cs: 10,10);
\end{scope}
\end{loglogaxis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{semilogyaxis}
\begin{scope}
\clip[] (axis cs: 0,0.1) rectangle (axis cs:10,10);
\addplot+[mark=none,domain=0.1:10,fill=blue!20!white] {x} -- (axis cs: 10,0.1) --(axis cs: 0.1,0.1);
\end{scope}
\end{semilogyaxis}
\end{tikzpicture}

\end{document}


Update: If the areas all the way down to the x-axis is preferred, this is how. The key is simply the choice of coordinates properly.

Code

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{pgfplots} % drawing plots right here in this file!
\pgfplotsset{compat=1.8} % latest stable release

\begin{document}

\pagestyle{empty}

\begin{tikzpicture}
\begin{loglogaxis}
\begin{scope}
\clip (axis cs: 0.1,0.01) rectangle (axis cs:10,10);
\addplot+[mark=none,domain=0.1:10,fill=blue!20!white] {x} --(axis cs: 10,0.05) -- (axis cs: 0.1,0.05);
\end{scope}
\draw[white](axis cs: 10,10)--(axis cs:10,0.05);
\end{loglogaxis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{semilogyaxis}
\begin{scope}
\clip (axis cs: 0,0.065) rectangle (axis cs:10,10);
\addplot+[mark=none,domain=0.1:10,fill=blue!20!white,smooth,draw] {x} -- (axis cs: 10,0.06) -- (axis cs: 0.1,0.06);