3

I have three lines drawn as \addplot functions in pgfplots. I want to restrict the domain of the lines based on their intersections. In the picture, I want to:

  1. plot the red line only between the black curves.
  2. plot the dashed line from 0 to the red curve.

Here is my code:

\documentclass[12pt, letterpaper]{article}
\usepackage{tikz,pgfplots,pgf}
\usetikzlibrary{intersections}
\usetikzlibrary{lindenmayersystems}
\pgfplotsset{mystyle/.style={%
        width=6cm,
        xmin=0,xmax=1,
        xtick={0,0.1,...,1}},
    ymin=0,ymax=1, enlarge x limits=false,
    ytick={0,0.2,...,1}}
%
\begin{document} 
    \begin{tikzpicture}
    \begin{axis}[domain=0:1,range=0:1,samples=100]
    \addplot[name path global=line2,mark=none,red] {(2*.0105 - (x*.055 + .03)*(1-.8)) / (.0105 + x*.055*(1-.8^40))};  
    \addplot[name path global=line1,mark=none] {(.0105 + x*.055*(.8 - .8^40) - .03*(1-.8)) / ( .0105 + x*.055*(.8 - .8^40))  };  
    \addplot[name path global=line3,mark=none,black,dashed] {(.055*x*(1-.8)) / .0105};  
    \end{axis}
    \end{tikzpicture}
\end{document}

Line Plot

3

You can clip line2 and line3 inside a rectangle with corners (0,0) and A-|B, where points A and B define intersection of line1 with line2 and line2 with line3 respectively

\documentclass[12pt, letterpaper]{article}
\usepackage{tikz,pgfplots,pgf}
\usetikzlibrary{intersections}
\usetikzlibrary{lindenmayersystems}
\pgfplotsset{mystyle/.style={%
    width=6cm,
    xmin=0,xmax=1,
    xtick={0,0.1,...,1}},
ymin=0,ymax=1, enlarge x limits=false,
ytick={0,0.2,...,1}}
%
\begin{document} 
\begin{tikzpicture}
\begin{axis}[domain=0:1,range=0:1,samples=100]
\addplot[name path global=line1,mark=none] {(.0105 + x*.055*(.8 - .8^40) - .03*(1-.8)) / ( .0105 + x*.055*(.8 - .8^40))  };  
\addplot[name path global=line2,draw=none] {(2*.0105 - (x*.055 + .03)*(1-.8)) / (.0105 + x*.055*(1-.8^40))};
\addplot[name path global=line3,draw=none] {(.055*x*(1-.8)) / .0105};  

\begin{scope}
\path [name intersections={of=line1 and line2,by=A}];
\path [name intersections={of=line2 and line3,by=B}];
\path[clip](0,0)rectangle(A-|B);
\addplot[name path global=line2,mark=none,red] {(2*.0105 - (x*.055 + .03)*(1-.8)) / (.0105 + x*.055*(1-.8^40))};
\addplot[name path global=line3,mark=none,black,dashed] {(.055*x*(1-.8)) / .0105};  
\end{scope}  
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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