TeX - LaTeX Asked by Arszilla on June 19, 2021
I’m trying to draw a basic graph in pgfplots
but facing an issue that I wasn’t able to solve based on similar posts. I’m trying to add the functions I’m displaying on my graph on their respective lines using nodes, but I end up getting the following result:
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
begin{tikzpicture}
begin{axis}[axis lines=center,
xlabel=$x$,
ylabel=$y$,
xmin=-1,
xmax=1.5,
ymin=-1,
ymax=2.5,
xtick distance=1,
clip=true,]
addplot[name path=A, thick, black, samples=200]{x} node[pos=0.61, right]{$y=x$};
addplot[name path=B, thick, black, samples=200]{x + 1} node[pos=0.61, right]{$y=x + 1$};
addplot[fill=red]fill between[of=A and B, soft clip={domain=0:1}];
end{axis}
end{tikzpicture}
As you can see from the image, y = x _+ 1
gets cut off, while y = x
is just at the edge of it, barely saving it. I tried setting clip=false
but my graph goes haywire, getting displaced from the center and going all over my page:
Is there a way to fix this?
Just add the domain to the functions
usepackage{pgfplots}
usepgfplotslibrary{fillbetween}
begin{tikzpicture}
begin{axis}[axis lines=center,
xlabel=$x$,
ylabel=$y$,
xmin=-1,
xmax=2,
ymin=-1,
ymax=2.5,
xtick distance=1]
addplot[name path=A, thick, black, samples=20, domain=-1:2]{x} node[pos=0.61, right]{$y=x$};
addplot[name path=B, thick, black, samples=20, domain=-1:2]{x + 1} node[pos=0.61, right]{$y=x + 1$};
addplot[fill=red]fill between[of=A and B, soft clip={domain=0:1}];
end{axis}
end{tikzpicture}
Correct answer by Alejandro Munoz Ossa on June 19, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP