Graphics, Figures & TablesFill Between of Graphs not working

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
coachbennett1981
Posts: 269
Joined: Fri Feb 05, 2010 10:15 pm

Fill Between of Graphs not working

Post by coachbennett1981 »

Hey Everyone,

I added a graph to my guided notes for students that just won't work. Here is my MWE

Code: Select all

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta}

\begin{document}

\begin{tikzpicture}
            \begin{axis}[
                            axis x line = center,
                                axis y line = center,
                                xmin = -5,   xmax = 5,
                                ymin = -2 , ymax =7,
                                xlabel={\(x\)},
                            ylabel={\(y\)},
                            xlabel style={above right},
                            ylabel style={above right},
                            axis line style={-                  latex[round],thick},
                            xtick distance=1,
                            ytick distance=1,
                            xticklabel style={font=\footnotesize},
                            tick label style={xshift=-0.2em},
                            tick style={major tick length=3mm,thick,color=black},    
                            yticklabel style={font=\footnotesize},               
             ]
             \addplot[name path=f,thick,domain=-4:4,smooth]{-.5*x^2+6};
             \addplot[name path=g,thick,domain=-4:4,smooth]{x^2};
            \addplot[blue,opacity=0.25]fill between[of=f and g,soft clip={domain=-2:2}];
            \end{axis}
        \end{tikzpicture}


\end{document}
The graph does work if I remove the \pgfplotsset command. Is there something I am missing? I am only filling between the intersection points of my graph. I have several other graphs in the same document that are all working fine. This is just the MWE of the graph.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
coachbennett1981
Posts: 269
Joined: Fri Feb 05, 2010 10:15 pm

Re: Fill Between of Graphs not working

Post by coachbennett1981 »

I removed the smooth option and replaced it with samples, and it works fine. No idea why that is.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10281
Joined: Mon Mar 10, 2008 9:44 pm

Re: Fill Between of Graphs not working

Post by Stefan Kottwitz »

It works with soft clip={domain=-2:1.9999}; possibly with the smooth option the filling sees more points after that range if you use exactly 2, but I did not investigate further.

Stefan
LaTeX.org admin
Post Reply