This question is related to this other question. Fill between fails to fill the correct region in this MWE.
\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{
every tick/.append style={thin},
axis x line=center,
axis y line=center,
xtick={-100,-99,...,100},
ytick={-100,-99,...,100},
xlabel=$x$,
ylabel=$y$,
xticklabel=\empty,
yticklabel=\empty,
xlabel style={at=(current axis.right of origin), anchor=west},
ylabel style={at=(current axis.above origin), anchor=south},
every tick label/.append style={font=\scriptsize},
axis equal image,
axis line style={black!66!white},
every axis plot/.append style={smooth,thick,mark=none,font=\small},
every node/.style={label font=\small},
every axis legend/.append style={at={(1,1)},anchor=south east,empty legend},
}
\pgfplotsset{rellenoa/.style={pattern=north west lines,pattern color=green,}}
\pgfplotsset{rellenob/.style={pattern=north east lines,pattern color=green,}}
\pgfplotsset{rellenoc/.style={pattern=horizontal lines,pattern color=green,}}
\begin{document}
\begin{center}
\begin{tikzpicture}
\def\xmi{-4.5} \def\xma{6.5} \def\ymi{-4.9} \def\yma{12.5}
\def\coa{-2} \def\cob{0.5} \def\coc{4}
\begin{axis}[
%scale=0.7, % this works
width=0.6\textwidth,xmin=\xmi,xmax=\xma,ymin=\ymi,ymax=\yma,y=1.5cm,
declare function={curvaa(\t)=-2*\t+4;},
declare function={curvab(\t)=2*\t+2;},
declare function={caminoa(\t)=-2*\t+1;},
declare function={caminob(\t)=2*\t-1;},]
%Lines
\addplot[domain=\xmi-1:\cob,samples=2,blue,name path=crva]{curvaa(x)};
\addplot[domain=\cob:\xma+1,samples=2,blue,name path=crvb]{curvab(x)};
\addplot[domain=\xmi-1:\cob,samples=2,purple]{caminoa(x)};
\addplot[domain=\cob:\xma+1,samples=2,purple]{caminob(x)};
%Points
\node[blue](X1t) at (axis cs:{\coa,caminoa(\coa)}) {};
\node[blue](X2t) at (axis cs:{\coa,curvaa(\coa)}) {};
\node[](X2m) at (axis cs:{\coa,curvaa(\cob)}) {};
\node[](X2b) at (axis cs:\coa,0) {};
\node[blue](X3t) at (axis cs:{\cob,curvaa(\cob)}) {};
\node[](X3b) at (axis cs:\cob,0) {};
\node[blue](X4t) at (axis cs:{\coc,curvab(\coc)}) {};
\node[](X4m) at (axis cs:{\coc,curvab(\cob)}) {};
\node[](X4b) at (axis cs:\coc,0) {};
\node[blue](X5t) at (axis cs:{\coc,caminob(\coc)}) {};
%Barriers
\draw[/pgfplots,red,dashed,] (X1t.center) -- (X2b.center);
\draw[/pgfplots,red,dashed,] (X5t.center) -- (X4b.center);
\draw[/pgfplots,red,dashed,] (X2t.center) -- (X2b.center);
\draw[/pgfplots,red,dashed,] (X4t.center) -- (X4b.center);
\path[name path=bed] (X2b.center)-- (X4b.center);
\draw[/pgfplots,red,dashed,name path=mid] (X2m.center) -- (X4m.center);
%Fills
\addplot[rellenoa] fill between [of=mid and crva,soft clip={domain=\coa:\cob},];
\addplot[rellenob] fill between [of=crvb and mid,soft clip={domain=\cob:\coc},];
\addplot[rellenoc] fill between [of=bed and mid,soft clip={domain=\coa:\coc},];
%Legends
%\legend{\empty,\empty,\empty,\empty,$A_1$,$A_2$,$A_3$}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
I've encountered this bug (maybe?) before, and I've dealt with it by playing around with the value of y
, but nothing seems to work with this one.
soft clip
, but I can see how this might be confusing. The left triangle works by accident. I added some more explanations to my answer, where I cite the relevant part of the manual.