\begin{center}
\begin{tikzpicture}[>=stealth,trim axis left, trim axis right]
\begin{axis}[legend style={at={(axis cs:40,20)},anchor=south west, draw=none},
xmin=0,xmax=4,
ymin=0,ymax=2,
axis x line=middle,
axis y line=middle,
axis line style=->,
xlabel={$x$},
ylabel={$y$},
]
\addplot[no marks,blue] expression[domain=0:3,samples=100]{(1/9) *x^2};
%\legend{$f(x)=frac{1}{9}x^2$}
\end{axis}
\end{tikzpicture}
\end{center}
如果我取消注释图例行,我的图片就不会出现在我的 pdf 中。有人知道为什么吗?
\legend{$f(x)=frac{1}{9}x^2$}
答案1
这是 的结果legend style
。您已将图例放置在轴限制之外。您看不到任何内容的原因可以通过\fill[red!20] (current bounding box.south east) rectangle (current bounding box.north west);
在 之前添加 来看到\end{tikzpicture}
。本质上,轴位于 tikzpicture 的左下角,图例位于右上角。但由于 太大tikzpicture
,您只能看到左上角,那里什么都没有。
at={(axis cs:40,20)},anchor=south west,
从 中删除label style
。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{center}
\begin{tikzpicture}[>=stealth,trim axis left, trim axis right]
\begin{axis}[
legend style={%at={(axis cs:40,20)},anchor=south west,
draw=none},
xmin=0,xmax=4,
ymin=0,ymax=2,
axis x line=middle,
axis y line=middle,
axis line style=->,
xlabel={$x$},
ylabel={$y$},
]
\addplot[no marks,blue] expression[domain=0:3,samples=100]{(1/9) *x^2};
\legend{$f(x)=\frac{1}{9}x^2$};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}