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 an old LaTeX user but just beginning to discover PGF and TikZ. I am trying to shade areas between 3 curves and from what I read I could do it with min and max functions, but forwhatever reasons my equations aren't liked by the compiler. So I tried using shadeareabetween function \usepgfplotslibrary{fillbetween} but that also wasn't liked by writeLaTeX or Mac compiler. So I had to subtract one curve from another manually but then I have to paint the lower area white and that spoils my axis ticks. Can you guys help me with this. Maybe show me a few tricks that can help this code a lot shorter. I am basically plotting 3 inflation rates from 8c at 2014.

Code:

\documentclass{article}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=newest}
\usetikzlibrary{intersections}
\usepackage{ wasysym }
\pagestyle{empty}
\usetikzlibrary{decorations.markings}
\begin{document}

\begin{tikzpicture}[scale =1.25,label/.style={%
   postaction={ decorate,transform shape,
   decoration={ markings, mark=at position .39 with \node #1;}}}]

    \begin{axis}[
    width=\textwidth,
      legend cell align=left,
    legend pos=outer north east,
    legend style={draw=none},
        %height=9cm,
        xlabel=Year,
        ylabel=\$/kWh,
       xmin=2004,   xmax=2050,
    ymin=5,   ymax=35,
    xticklabel style={/pgf/number format/1000 sep=},
        %width=9cm,
        xtick={2005,  2010, 2013, 2020, 2030, 2040,2050},
        xticklabels={05,10,13,2020,2030,2040,2050},
    ytick={6,8,10,15,...,30},
    ]

    %\addplot {8*1.08^x};
    %\addlegendentry{8\%}

    \addplot[   color=black,
                solid,
                mark=*,
                mark options={solid},
                smooth] coordinates {
        (2005,6)
        (2006,7.32)
        (2007,9.42)
        (2008,10.29)
        (2009,8.09)
        (2010,6.73)
        (2011,9.60)
        (2012,9.62)
        (2013,8.66)
        (2014,8)

    };
    \addlegendentry{Retail}




\addplot+[mark=none,draw=none,fill=orange!70,domain=2014:2050] {8*1.07^(x-2014)}\closedcycle;

\addplot+[mark=none,draw=none,fill=white,domain=2014:2050] {8*1.03^(x-2014)}\closedcycle;




\addplot[name path global=T,color=black,line width=0.75,dashed,domain=2013.75:2050,label={[below]{3\%}}]{8.*(1.03)^( x -  2014 )};
    %\addlegendentry{3\% inflation}

    \addplot[label={[below]{5\%}},name path global = F,color=black,line width=0.75,dashed,domain=2013.85:2048,]{8.*(1.05)^( x -  2014 )};
    %\addlegendentry{5\% inflation}

    \addplot[label={[below]{7\%}},name path global=S,color=black,line width=0.75,dashed,domain=2013.85:2050]{8.*(1.07)^( x -  2014 )};


\end{axis}


\end{tikzpicture}

\end{document}
share|improve this question
    
Welcome to TeX.SX! –  Heiko Oberdiek Apr 27 at 20:46

2 Answers 2

Use the option axis on top for the axis environment:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=newest}
\usetikzlibrary{intersections}
\usepackage{ wasysym }
\pagestyle{empty}
\usetikzlibrary{decorations.markings}
\begin{document}

\begin{tikzpicture}[scale =1.25,label/.style={%
   postaction={ decorate,transform shape,
   decoration={ markings, mark=at position .39 with \node #1;}}}]

    \begin{axis}[
    axis on top,
    width=\textwidth,
      legend cell align=left,
    legend pos=outer north east,
    legend style={draw=none},
        %height=9cm,
        xlabel=Year,
        ylabel=\$/kWh,
       xmin=2004,   xmax=2050,
    ymin=5,   ymax=35,
    xticklabel style={/pgf/number format/1000 sep=},
        %width=9cm,
        xtick={2005,  2010, 2013, 2020, 2030, 2040,2050},
        xticklabels={05,10,13,2020,2030,2040,2050},
    ytick={6,8,10,15,...,30},
    ]

    %\addplot {8*1.08^x};
    %\addlegendentry{8\%}

    \addplot[   color=black,
                solid,
                mark=*,
                mark options={solid},
                smooth] coordinates {
        (2005,6)
        (2006,7.32)
        (2007,9.42)
        (2008,10.29)
        (2009,8.09)
        (2010,6.73)
        (2011,9.60)
        (2012,9.62)
        (2013,8.66)
        (2014,8)

    };
    \addlegendentry{Retail}




\addplot+[mark=none,draw=none,fill=orange!70,domain=2014:2050] {8*1.07^(x-2014)}\closedcycle;

\addplot+[mark=none,draw=none,fill=white,domain=2014:2050] {8*1.03^(x-2014)}\closedcycle;




\addplot[name path global=T,color=black,line width=0.75,dashed,domain=2013.75:2050,label={[below]{3\%}}]{8.*(1.03)^( x -  2014 )};
    %\addlegendentry{3\% inflation}

    \addplot[label={[below]{5\%}},name path global = F,color=black,line width=0.75,dashed,domain=2013.85:2048,]{8.*(1.05)^( x -  2014 )};
    %\addlegendentry{5\% inflation}


    \addplot[label={[below]{7\%}},name path global=S,color=black,line width=0.75,dashed,domain=2013.85:2050]{8.*(1.07)^( x -  2014 )};


\end{axis}


\end{tikzpicture}

\end{document}

enter image description here

I changed to the standalone class just for the example to avoid an overfull box (your image is too wide for standard margins).

share|improve this answer

You can also use fill between, but the solution is fragile.

\documentclass{article}
\usepackage{pgfplots,tikz}
\pgfplotsset{compat=newest}
\usetikzlibrary{intersections}
\usepackage{ wasysym }
\pagestyle{empty}
\usetikzlibrary{decorations.markings}
\usepgfplotslibrary{fillbetween}% note addition
\begin{document}

\noindent
\begin{tikzpicture}[label/.style={%
   postaction={ decorate,transform shape,
   decoration={ markings, mark=at position .2 with \node #1;}}}]

    \begin{axis}[
      width=\textwidth,
      legend cell align=left,
      legend pos=outer north east,
      legend style={draw=none},
      %height=9cm,
      xlabel=Year,
      ylabel=\$/kWh,
      xmin=2004,   xmax=2050,
      ymin=5,   ymax=35,
      %xticklabel style={/pgf/number format/1000 sep=},
      %width=9cm,
      xtick={2005,  2010, 2013, 2020, 2030, 2040,2050},
      xticklabels={05,10,13,2020,2030,2040,2050},
      ytick={6,8,10,15,...,30},
    ]

    %\addplot {8*1.08^x};
    %\addlegendentry{8\%}

    \addplot[   color=black,
                solid,
                mark=*,
                mark options={solid},
                smooth] coordinates {
        (2005,6)
        (2006,7.32)
        (2007,9.42)
        (2008,10.29)
        (2009,8.09)
        (2010,6.73)
        (2011,9.60)
        (2012,9.62)
        (2013,8.66)
        (2014,8)
    };
    \addlegendentry{Retail}

\addplot[name path=S,draw=none,mark=none,domain=2013.85:2050] {8.*(1.07)^( x -  2014 )};
%\addplot[name path=F,draw=none,mark=none,domain=2013.85:2050] {8.*(1.05)^( x -  2014 )};
\addplot[name path=T,draw=none,mark=none,domain=2013.85:2050] {8.*(1.03)^( x -  2014 )};
\addplot[orange] fill between[of=S and T];

\addplot[color=black,line width=0.75,dashed,label={[below]{7\%}},domain=2013.85:2050] {8.*(1.07)^( x -  2014 )};
\addplot[color=black,line width=0.75,dashed,label={[below]{5\%}},domain=2013.85:2050] {8.*(1.05)^( x -  2014 )};
\addplot[color=black,line width=0.75,dashed,label={[below]{3\%}},domain=2013.85:2050] {8.*(1.03)^( x -  2014 )};

\end{axis}

\end{tikzpicture}

\end{document}

note labels

share|improve this answer

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.