Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
    \addplot+[mark=none,domain=0.1:10] {x} ;
    \addplot[domain=0.3:7,fill=black]  {x} \closedcycle;  
  \end{loglogaxis}
\end{tikzpicture}

\end{document}

sample plot

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?

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

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
    \addplot+[mark=none,domain=0.1:10] {x} ;
    \addplot[domain=0.3:7,fill=black]  {x} \closedcycle;  
  \end{loglogaxis}
\end{tikzpicture}

\end{document}

Output

enter image description here

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+[mark=none,domain=0.1:10]   {x} ;
    \addplot[domain=0.3:7,name path=A]    {x};  
    \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.)

share|improve this answer
add comment

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.

enter image description here

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);
%    \addplot[domain=0.3:7,fill=black]  {x} \closedcycle;  
\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);
%%    \addplot[domain=0.3:7,fill=black]  {x} \closedcycle;  
\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.

enter image description here

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);
%    \addplot[domain=0.3:7,fill=black]  {x} \closedcycle;  
\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);
%%    \addplot[domain=0.3:7,fill=black]  {x} \closedcycle;  
\end{scope}
\draw[white](axis cs: 10,10)--(axis cs:10,0.065);
\end{semilogyaxis}
\end{tikzpicture}

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.