I have the following code that I am using in pgfplots
in a standalone tikz
document:
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{positioning, arrows.meta}
\pgfplotsset{every axis/.append style={
tick label style={font=\footnotesize},
}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=both,
xmin=-1.5, xmax=9.997,
ymin=-1.9975, ymax=5.9975,
axis lines=middle,
xlabel=\(x\), ylabel=\(y\),
xticklabels={}, yticklabels={},
clip=false,
y axis line style={Stealth-Stealth},
x axis line style={Stealth-Stealth}
]
% graph curve
\addplot[stealth-stealth, domain=-2.15:4.15, samples=50] ({x^2-2*x}, {x+1});
% points on curve
\node [circle, fill=black, scale=0.4, label=below left:{\(t=0\)}] at (0, 1) {};
\node [circle, fill=black, scale=0.4, label=below left:{\(t=-2\)}] at (8, -1) {};
\node [circle, fill=black, scale=0.4, label=above left:{\(t=2\)}] at (0, 3) {};
\node [circle, fill=black, scale=0.4, label=above left:{\(t=4\)}] at (8, 5) {};
% orientation of curve, code from https://tex.stackexchange.com/a/142650/296881
\def\NORM{sqrt((2*t-2)^2 + 1^2)}
\addplot[thick,-latex, , samples=6, domain=-1.5:3.5, variable=\t,quiver={
u=(2*t-2)/\NORM, v=1/\NORM,
scale arrows=0.1,
}]
({t^2-2*t}, {t+1});
\end{axis}
\end{tikzpicture}
\end{document}
This is the entire document. I expected it to look like this:
When I run the code within the tikzpicture
environment with \documentclass{article}
, that is what I get, the correct result. However, when I run the above code with \documentclass[tikz]{standalone}
, I get that all of the nodes are clumped together at the bottom left like this:
How do I fix this?
\pgfplotsset{compat=newest}
(you should get a warning that suggests doing this actually)? The reason is that only in newer versions, the coordinates inside anaxis
environment are also valid for\draw
or other "normal" TikZ commands, but for older versions they are not and you would need to type(axis cs:1,1)
instead for just(1,1)
.\documentclass{article}
. Your article code must be slightly different.\pgfplotsset{compat=newest}
in the\documentclass{article}
but not the\documentclass[tikz]{standalone}