2

I'm trying to use the method outline in Graphics: Area between curves to create a graph of the area between two curves to insert into a solution sheet. However, when I do, the box is placed incorrectly. The tikzpicture ends up way higher than it should be, rather than being in line, and so covers up text, or other pictures placed above it. My code is as follows:

\documentclass[11pt]{article}

\usepackage{tikz}
\usepackage{pgfplots}

\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\begin{document}
The box for the tikzpicture appears to be much higher than it should be.\\
{\begin{tikzpicture}[scale=0.75]
\begin{axis}[
xmin=0,xmax=5,
    ymin=-1, ymax=6,
        xtick = {-1,1},
    ytick = {1,2,3,4,5,6},
    axis lines=center,
    axis line style = <->,
        ticklabel style = {font=\small}
]

\addplot[name path=F,domain={0:5}] {x};
\addplot[name path=G,domain={0:5}] {(x-2)^2};
\addplot[pattern=north west lines, pattern color=gray!50]fill between[of=F and G, soft clip={domain=1:4}];
\end{axis}
\end{tikzpicture}}
\end{document}
  • 1
    This seems to be a "scaling" problem/bug. If you comment the scaleing factor or set it to 1 everything seems to work fine. – Stefan Pinnow Feb 14 '17 at 21:11
1

As I already stated in the comment below the question I consider this being a bug which I have reported to the PGFPlots Tracker.

There is a workaround to get the desired result. Have a look at the comments in the code on how to do it.

\documentclass[11pt]{article}
\usepackage{pgfplots}
    \usetikzlibrary{
        patterns,
        pgfplots.fillbetween,
    }
\begin{document}
The box for the tikzpicture appears to be much higher than it should be.

\begin{tikzpicture}[
% this line causes the mess ...
%    scale=0.75,
]
    \begin{axis}[
        % ... as a workaround just scale the default axis `width' directly with
        % the factor to get the desired result
        width=0.75*\axisdefaultwidth,
        xmin=0,     xmax=5,
        ymin=-1,    ymax=6,
        xtick={-1,1},
        ytick={1,2,3,4,5,6},
        axis lines=center,
        axis line style=<->,
        ticklabel style={font=\small}
    ]
        \addplot [name path=F,domain={0:5}] {x};
        \addplot [name path=G,domain={0:5}] {(x-2)^2};
        \addplot [
            pattern=north west lines,
            pattern color=gray!50,
        ] fill between [
            of=F and G,
            soft clip={domain=1:4},
        ];
    \end{axis}
\end{tikzpicture}
\end{document}

image showing a zoomed region of the above code

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.