Fill area Between Two Lines with Only One Intersection

fillbetweentikz-pgf

I am trying to fill the area between these two lines that only connect one one end.

\documentclass{beamer}

\usetheme{Berkeley}%{Marburg}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usepackage{amsmath}
\usepackage{nicefrac}
\usepackage{pgfplots}% loads also tikz
\usepackage{multirow}
\pgfplotsset{compat=newest}% to avoid the pgfplots warning
\usetikzlibrary{intersections}
\usepgfplotslibrary{fillbetween}
\pgfdeclarelayer{pre main}

\begin{document}
\begin{frame}
        \begin{tikzpicture}[scale =1.3]
        \draw [step=.25,gray,very thin] (0,0)grid(5,5);
    
    
    \node [right] at (5.1,2.2) {\rotatebox{90}{\scriptsize Sense-Object $S$}};
    \node [below,left] at (2.8,-.3) {\scriptsize Sense-Object $R$};
    
    \node [align=right] at (5.6,4.8) {\scriptsize Origin for\\ \scriptsize Person $1$};
    \node [align=right] at (-.7,.7) {\scriptsize Origin for\\\scriptsize Person $2$};
    
    %initial endowment
    %\node [circle, fill=blue] at (2.5,3){};
    \fill[red] (.5,4.25) circle (1.5pt);
    \draw[red, thick, name path = A] plot [smooth] coordinates {(.5,4.25)(2.5,4.1)(4.75,3.05)};
    \draw[blue, thick, name path = B] plot [smooth] coordinates {(.5,4.25)(2.75,2.75)(5,2.37)};
    \fillbetween[of=A and B];
    \end{tikzpicture}
\end{frame}
    \end{document}

I am simply trying to fill the area between the red and blue lines with a partial transparent color. I want the filling to end just at the end of the red line.

Best Answer

fillbetween can only be used inside pgfplots environment, so here you have to add \usetikzlibrary{pgfplots.fillbetween}. Then, with a bit of cheating (creating a third path, named B and ending at x=4.75) you get this:

fill tikz in between

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz}
    \usetikzlibrary{patterns}
    \usepackage{amsmath}
    \usepackage{nicefrac}
    \usepackage{pgfplots}% loads also tikz
    \usepackage{multirow}
    \pgfplotsset{compat=newest}% to avoid the pgfplots warning
    \usetikzlibrary{intersections,pgfplots.fillbetween}
    \usepgfplotslibrary{fillbetween}
    \pgfdeclarelayer{pre main}

    \begin{document}
        \begin{tikzpicture}[scale =1.3]
        \draw [step=.25,gray,very thin] (0,0)grid(5,5);
    
    
    \node [right] at (5.1,2.2) {\rotatebox{90}{\scriptsize Sense-Object $S$}};
    \node [below,left] at (2.8,-.3) {\scriptsize Sense-Object $R$};
    
    \node [align=right] at (5.6,4.8) {\scriptsize Origin for\\ \scriptsize Person $1$};
    \node [align=right] at (-.7,.7) {\scriptsize Origin for\\\scriptsize Person $2$};
    
    %initial endowment
    %\node [circle, fill=blue] at (2.5,3){};
    \fill[red] (.5,4.25) circle (1.5pt);
    
    \draw[red, thick, name path = A] plot [smooth] coordinates {(.5,4.25)(2.5,4.1)(4.75,3.05)};
    \draw[blue, thick] plot [smooth] coordinates {(.5,4.25)(2.75,2.75)(5,2.37)};
    \path[name path = B] plot [smooth] coordinates {(.5,4.25)(2.75,2.75)(4.75,2.38)};
    
    
    \tikzfillbetween[of=A and B]{blue, opacity=0.2};
    \end{tikzpicture}

    \end{document}
Related Question