设置全局轴选项 PGFPLOTS

设置全局轴选项 PGFPLOTS

由于某种原因,在使用 tikz 库矩阵绘制全局图例时,使用 pgfplotsset 设置全局选项不起作用。图例实际上根本没有显示,所以出了问题。我只需要为三个条目绘制图例。

\documentclass{article}
\usepackage[margin=0.25in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usepackage{pgfplots}
\usepgfplotslibrary{external} 
\pgfplotsset{width=10cm,
            compat=1.9,
            }

\tikzexternalize

\begin{document}

\begin{tikzpicture}
            
\pgfplotsset{xlabel style={xlabel=$x$, label style={font=\HUGE}}, 
            every axis plot/.style={line width=5.5pt},
            every axis post/.append style={xmin=-10, xmax=10}}

\begin{axis}[name=t1, height=5cm, width=10cm]
\addplot[color=red] table[x=time, y=d1]{distances1.dat};\label{plots:dissociated}
\addplot[color=blue] table[x=time, y=d2]{distances1.dat};\label{plots:bound}
\end{axis}

\begin{axis}[name=t1a, at={($(t1.east)+(1cm,0cm)$)}, anchor=west, height=5cm, width=10cm]
\addplot[color=green] table[x=time, y=d3]{distances1.dat};\label{plots:angle}
\end{axis}

\begin{axis}[name=t2, at={($(t1.south)+(0cm,0cm)$)}, anchor=north, height=5cm, width=10cm]
\addplot[color=red] table[x=time, y=d1]{distances2.dat};
\addplot[color=blue] table[x=time, y=d2]{distances2.dat};
\end{axis}

\begin{axis}[name=t2a, at={($(t2.east)+(1cm,0cm)$)}, anchor=west, height=5cm, width=10cm]
\addplot[color=green] table[x=time, y=d3]{distances2.dat};
\end{axis}


\begin{axis}[name=t3, at={($(t2.south)+(0cm,-1cm)$)}, anchor=north, height=5cm, width=10cm]
\addplot[color=red] table[x=time, y=d1]{distances3.dat};
\addplot[color=blue] table[x=time, y=d2]{distances3.dat};
\end{axis}

\begin{axis}[name=t3a, at={($(t3.east)+(1cm,0cm)$)}, anchor=west, height=5cm, width=10cm]
\addplot[color=green] table[x=time, y=d3]{distances3.dat};
\end{axis}

\begin{axis}[name=t4, at={($(t3.south)+(0cm,0cm)$)}, anchor=north, height=5cm, width=10cm]
\addplot[color=red] table[x=time, y=d1]{distances4.dat};
\addplot[color=blue] table[x=time, y=d2]{distances4.dat};
\end{axis}

\begin{axis}[name=t4a, at={($(t4.east)+(1cm,0cm)$)}, anchor=west, height=5cm, width=10cm]
\addplot[color=green] table[x=time, y=d3]{distances4.dat};
\end{axis}

\coordinate (bot) at (rel axis cs:1,0);

\matrix[
    matrix of nodes,
    anchor=south,
    draw,
    line width=1pt,
    inner sep=0.2em,
    draw
  ]at([yshift=-5ex]legendpos)
  {
    \ref{plots:dissociated}& Dissociated &[5pt]
    \ref{plots:bound}& Bound &[5pt]
    \ref{plots:angle} & Angle &[5pt]\\};`

\end{tikzpicture}

有谁知道如何正确绘制图例,以及为什么使用矩阵会影响使用 pgfplotsset 设置全局选项?

答案1

欢迎来到 TeX:SE!

由于您没有提供文件,distances1.dat我们无法测试您的文档示例(它也包含一些错误,请再次检查)。但是,这有效:

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{
    compat=1.18,
    %
    height=5cm, width=10cm,
    xlabel=$x$, label style={font=\huge},
    every axis plot post/.append style={line width=5.5pt},
    xmin=-10,
    xmax=10
            }

\begin{document}
    \begin{tikzpicture}
\begin{axis}[domain=-9:9, samples=11]
    \addplot    {x};
    \addplot    {2*x};
\end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

如果我\pgfplotsset的页面可以正常工作,您需要自己测试一下(但我看不出有什么理由不这样做)。

相关内容