pgfplots 背景著色的選項

pgfplots 背景著色的選項

我一直在尋找一個簡單的答案,但沒有成功。我想繪製函數 y=x^2,並為環境組成的整個盒子的背景著色axis。直覺上,人們會認為有一個fill選項可用於axis,但事實證明並非如此!難道沒有簡單的解決方法嗎?另外,如果我想將顏色擴展到盒子之外怎麼辦axis

當然,也可以手動添加一個矩形並根據需要調整其尺寸,但這並不方便。

\documentclass{article}
\usepackage{tikzplot}
\begin{document}
   \begin{tikzpicture}
      \begin{axis}[fill = grey!10,] % This option does not work, why????
         \addplot {x^2};
      \end{axis}

   \end{tikzpicture}
\end{document} 

答案1

從 pgfplots 文件的第 95 頁開始。axis background/.style為了環境而使用axis

在此輸入影像描述

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
   \begin{tikzpicture}
      \begin{axis}[axis background/.style={fill=gray!10}]
         \addplot {x^2};
      \end{axis}
   \end{tikzpicture}
\end{document}

相關內容