1

I have 4 plots, depicting three subtle different behaviors.

\documentclass{article}
\usepackage{filecontents}
\usepackage{cleveref}
\begin{filecontents}{testdata.dat}
t    phi
0    5
10   15
20   25
30   20
40   35
\end{filecontents}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\usepgfplotslibrary{groupplots}
\pgfplotsset{every axis/.append style={
                    label style={font=\tiny},
                    tick label style={font=\tiny}
}, width=0.3\textwidth}

\begin{figure}
\begin{tikzpicture}
  \begin{groupplot}[group style={group name=my plots,group size= 2 by
      2, vertical sep=1.5cm },height=5cm,width=6.4cm]

  \nextgroupplot
  \addplot [color=blue] table [x={t}, y={phi}] {testdata.dat};
  \label{plot:1}

  \nextgroupplot
  \addplot [color=green] table [x={t}, y={phi}] {testdata.dat};
  \label{plot:2}

  \nextgroupplot
  \addplot [color=red] table [x={t}, y={phi}] {testdata.dat};
  \label{plot:3}

  \nextgroupplot
  \addplot [color=blue] table [x={t}, y={phi}] {testdata.dat};
  \label{plot:4}
\end{groupplot}
\end{tikzpicture}
\label{fig:plots}
\caption{Some Plots}
\end{figure}

As you can see in \Cref{plot:1,plot:3} \ldots
\end{document}

The thing is, I want them to be plotted next to each other in order to show their (sometimes subtle) differences. In the text to follow, however, I need to reference each subplot individually. Hence, I would like to label them with numbers, letters or whatever and later on \Cref{} them. This reference should be resolved in a hierarchical manner, i.e. it should read something like "Figure 1, Plot 2".

Is something like this even possible?

1

Something like this?

enter image description here

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{testdata.dat}
t    phi
0    5
10   15
20   25
30   20
40   35
\end{filecontents}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\pgfplotsset{
  every axis/.append style={
      label style={font=\tiny},
      tick label style={font=\tiny}
     },
  width=0.3\textwidth,
}


\newcounter{plot}[figure]

\newcommand{\AddLabel}[1]{%
\node [below right] at (rel axis cs:0,1) {\refstepcounter{plot}\label{#1}\ref{#1})};
}

\usepackage{cleveref}
\crefname{plot}{plot}{plots}
\Crefname{plot}{Plot}{Plots}

\begin{document}


\begin{figure}
\begin{tikzpicture}
  \begin{groupplot}[group style={group name=my plots,group size= 2 by
      2, vertical sep=1.5cm },height=5cm,width=6.4cm]

  \nextgroupplot
  \addplot [color=blue] table [x={t}, y={phi}] {testdata.dat};
  \AddLabel{plot:1}

  \nextgroupplot
  \addplot [color=green] table [x={t}, y={phi}] {testdata.dat};
  \AddLabel{plot:2}

  \nextgroupplot
  \addplot [color=red] table [x={t}, y={phi}] {testdata.dat};
  \AddLabel{plot:3}

  \nextgroupplot
  \addplot [color=blue] table [x={t}, y={phi}] {testdata.dat};
  \AddLabel{plot:4}
\end{groupplot}
\end{tikzpicture}
\label{fig:plots}
\caption{Some Plots}
\end{figure}

As you can see in \Cref{plot:1,plot:3} \ldots
\end{document}
  • That solves the problem about referencing them at all. Thanks. Do you know, if it is possible to reference them hierarchically? (i.e. get "Plots 1 and 2 in Figure 1" automatically?) – choeger Oct 22 '16 at 10:55
  • @choeger No, I don't, sorry. You'd need to do \cref{plot:1,plot:2} in \cref{fig:1} with my code. – Torbjørn T. Oct 23 '16 at 19:07
1

Here a solution using the \phantomsubcaption and \subref commands from the subcaption package. It does not exactly do what you want, but I think this gives shorter labels and so is worth showing it.

For simplicity I created the new command \SubLabel to place the labels, so they always appear the same.

    \begin{filecontents}{testdata.dat}
        t    phi
        0    5
        10   15
        20   25
        30   20
        40   35
    \end{filecontents}
\documentclass{article}
\usepackage{subcaption}
\usepackage{pgfplots}
    \usepgfplotslibrary{
        groupplots,
    }
\usepackage{cleveref}
    \newcommand*\SubLabel[1]{
        \node [
            anchor=north west,
            text width=2em,
            text height=2ex,
            text depth=1ex,
            align=left,
        ] at (axis description cs:0.02,0.98)
            {\phantomsubcaption\label{#1}\subref{#1})};
    }
\begin{document}
    \begin{figure}
        \begin{tikzpicture}
            \begin{groupplot}[
                group style={
                    group name=my plots,
                    group size= 2 by 2,
                    vertical sep=1.5cm,
                },
                height=5cm,
                width=6.4cm,
            ]
            \nextgroupplot
                \addplot [color=blue] table [x={t}, y={phi}] {testdata.dat};
                    \SubLabel{plot:1};
            \nextgroupplot
                \addplot [color=green] table [x={t}, y={phi}] {testdata.dat};
                    \SubLabel{plot:2};
            \nextgroupplot
                \addplot [color=red] table [x={t}, y={phi}] {testdata.dat};
                    \SubLabel{plot:3};
            \nextgroupplot
                \addplot [color=blue] table [x={t}, y={phi}] {testdata.dat};
                    \SubLabel{plot:4};
            \end{groupplot}
        \end{tikzpicture}
        \caption{Some Plots}
            \label{fig:plots}
    \end{figure}

    As you can see in \crefrange{plot:1}{plot:3} \ldots
\end{document}

image showing the result of above code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.