我想要使​​用 pgfplots 创建的整个图的背景

我想要使​​用 pgfplots 创建的整个图的背景

我用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}

相关内容