7

I couldn't find a simple way to fill the area of the intersections of 3 curves. I want to fill this area:

enter image description here

My try:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfplotsset{my style1/.append style={clip = false, axis lines* = middle, axis equal, xtick = \empty, ytick = \empty}}

\usepgfplotslibrary{fillbetween}

\usepackage{tikz}
\usetikzlibrary{calc, math, positioning, arrows, intersections} 
 
\begin{document}
    
\begin{tikzpicture}
    \begin{axis}[my style1, samples=150]
        \addplot [domain=0:1.5, name path=c1] ({x},{x^2+0.2});
        \addplot [domain=0:1.5, name path=c2] ({x},{sqrt(x)+0.2});
        \addplot [name path=c3] coordinates {(0.3,0.5)(1.3,0.5)(1.3,0.9)(0.3,0.9)(0.3,0.5)};
        %\addplot [blue] fill between[of=c1,c2 and c3];
        
    \end{axis}
\end{tikzpicture}
    
\end{document}

But it seems like fill between only can fill the intersection of 2 curves. Any help would be appreciated.

5

It seems the soft clip option from pgfplots is not sufficient here, hence I use a \fill following \clip.

Full example

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pgfplotsset{my style1/.append style={clip = false, axis lines* = middle, axis equal, xtick = \empty, ytick = \empty}}

\usepgfplotslibrary{fillbetween}

\usepackage{tikz}
\usetikzlibrary{calc, math, positioning, arrows, intersections} 
 
\begin{document}
    
\begin{tikzpicture}
    \begin{axis}[my style1, samples=150]
        \addplot [domain=0:1.5, name path=c1] ({x},{x^2+0.2});
        \addplot [domain=0:1.5, name path=c2] ({x},{sqrt(x)+0.2});
        \addplot [name path=c3] coordinates {(0.3,0.5)(1.3,0.5)(1.3,0.9)(0.3,0.9)(0.3,0.5)};
        
        % \clip will act on all the following paths in the current scope
        \clip (.3,.5) rectangle (1.3,.9);
        \fill[blue] (0, 0) plot[domain=0:1.5] (\x, \x^2+.2) 
                        -- plot[domain=1.5:0] (\x, {sqrt(\x)+.2}) -- (0, 0);
    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

| improve this answer | |
  • The left corner is supposed to be fill. And you said a thing that is not coherent: pgf v3.1.6 contains a problem but v3.1.6 has fixed this problem – Á. Iborra Oct 2 at 6:51
  • @Iborra Looks like soft clip is not sufficient here. And the second v3.1.6 should be v3.1.6a. I will delete this answer. – muzimuzhi Z Oct 2 at 7:42
  • @Iborra My answers is updated and a tikz workaround is provided. – muzimuzhi Z Oct 2 at 8:04
  • The initial (0,0) and the final -- (0,0) are unnecesary – Á. Iborra Oct 3 at 15:40

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.