![我想要使用 pgfplots 创建的整个图的背景](https://linux22.com/image/373255/%E6%88%91%E6%83%B3%E8%A6%81%E4%BD%BF%E2%80%8B%E2%80%8B%E7%94%A8%20pgfplots%20%E5%88%9B%E5%BB%BA%E7%9A%84%E6%95%B4%E4%B8%AA%E5%9B%BE%E7%9A%84%E8%83%8C%E6%99%AF.png)
我用pgfplots
它来为我的文档创建一些简单的图表。我希望整个文档都有淡黄色的背景。我这样做了:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis background/.style={fill=yellow!30},
axis lines=middle,
every axis x label/.style={at={(current axis.right of origin)},anchor=west},
every axis y label/.style={at={(current axis.above origin)},anchor=south},
xlabel={$x$},
xtick=\empty,
ylabel={$y$},
ytick=\empty,
]
\addplot [red,thick] plot {\x^2};
\end{axis}
\end{tikzpicture}
\end{document}
这给了我以下
黄色背景在轴停止的地方停止。在我看来,这看起来不像是一个合适的背景。我希望黄色方块在各个方面都稍微大一点。另外,黄色方块至少也应该位于 x 和 y 的后面。
为了了解我想要什么,这是我试图模仿的风格:
如何才能获得更好的背景?
答案1
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{shadows.blur}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
every axis x label/.style={at={(current axis.right of origin)},anchor=west},
every axis y label/.style={at={(current axis.above origin)},anchor=south},
xlabel={$x$},
xtick=\empty,
ylabel={$y$},
ytick=\empty,
]
\addplot [red,thick] plot {\x^2};
\end{axis}
\begin{pgfonlayer}{background}
\draw[fill=yellow!20,blur shadow={shadow blur steps=5,shadow xshift=-1mm},fill=yellow!30]
([xshift=-3mm,yshift=-3mm]current axis.south west) rectangle
([xshift=5mm,yshift=5mm]current axis.north east);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{shadows}
\usetikzlibrary{shadows.blur}
\pgfdeclarelayer{background}
\pgfsetlayers{background,main}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% axis background/.style={fill=yellow!30},
axis lines=middle,
every axis x label/.style={at={(current axis.right of origin)},anchor=west},
every axis y label/.style={at={(current axis.above origin)},anchor=south},
xlabel={$x$},
xtick=\empty,
ylabel={$y$},
ytick=\empty,
]
\addplot [red,thick] plot {\x^2};
\begin{pgfinterruptboundingbox}
\begin{pgfonlayer}{background}
\draw[blur shadow={shadow blur steps=5,shadow xshift=-1mm},fill=yellow!30] \pgfextra{\pgfplotspathaxisoutline};
\end{pgfonlayer}
\end{pgfinterruptboundingbox}
\end{axis}
\end{tikzpicture}
\end{document}