PGFplotsSet
配置环境与全局/局部样式
版本配置
\pgfplotsset
命令可以为PGFplots指定版本,一般写在\begin{document}
之前。
通常可以用\pgfplotsset{compat=newest}
来引入最新版本。
如果想指定版本,可以用\pgfplotsset{compat=1.18}
,其中 1.18 是截止此文档撰写时官方文档的最新版本。
WARNING
官方文档中指出:版本号至少应设置为 1.3 版。否则,PGFplots 会认为您的文档是多年前生成的,并尝试尽可能以向后兼容的模式运行。
上下文配置
\pgfplotsset
命令还可以为元素统一配置某些键值,比如用 every xxx/.style={...}
为 xxx 配置 style。
以下是两种写法的区别:
latex
\pgfplotsset{every axis/.style={...}} % 替换样式
\pgfplotsset{every linear axis/.append style={...}} % 添加样式
也可以直接写键值对:
latex
\pgfplotsset{
cycle list={
{red, mark=*}, {blue,mark=*},
{red, mark=x}, {blue,mark=x},
{red, mark=square*}, {blue,mark=square*},
{red, mark=triangle*}, {blue,mark=triangle*},
{red, mark=diamond*}, {blue,mark=diamond*},
{red, mark=pentagon*}, {blue,mark=pentagon*}
},
legend style={
at={(0.5,-0.2)},
anchor=north,
legend columns=2,
cells={anchor=west},
font=\footnotesize,
rounded corners=2pt,
},
xlabel=$x$,
ylabel=$f(x)$,
}
\pgfplotsset
可配置的具体内容请查看相关元素介绍。
生效范围
\pgfplotsset
写在 \begin{document}
之前表示全局生效,优先级小于本地配置。
如果是写在某个块中,如:
latex
\begin{figure}
\pgfplotsset{...}
\end{figure}
表示仅对该 figure
的上下文中生效。