I have two plots I would like to put in a grouppolt
environment with a unique legend. Each plot is generated by a given set of data using the command \pgfplotstableread{directory}{\DataTable}
.
Now let's imagine we have the following code structure for each plot:
\begin{figure}[htbp]
\centering
\pgfplotstableread{directory}{\DataTable}
\begin{tikzpicture}
\begin{axis}[
title = Time evolution of mass,
xmin = 0, xmax = 42,
ymin = 0.3, ymax = 1.05,
xtick distance = 5,
ytick distance = 0.2,
xlabel={$time\;[s]$},
ylabel={$mass$},
grid = both,
grid style = {dotted},
minor tick num = 1,
major grid style = {lightgray!75},
minor grid style = {lightgray!75},
width = 0.85\textwidth,
height = 0.50\textwidth,
%scale only axis,
legend cell align = {left},
legend pos = north east
]
\addplot[smooth, black, ultra thick] table [x = {t1a}, y = {m1a}] {\DataTable};
\addplot[smooth, Lavender, very thick] table [x = {t1b}, y = {m1b}] {\DataTable};
\addplot[smooth, Violet, very thick] table [x = {t1c}, y = {m1c}] {\DataTable};
\addplot[smooth, Emerald, dotted, ultra thick] table [x = {t2}, y = {m2}] {\DataTable};
\legend{
n1 (k),
n1 (k-2),
n1 (k-4),
n2,
}
\draw[-{Circle[open, width=4pt, length=4pt]}, shorten >=-2pt,shorten <=0mm] (rel axis cs:0.5,0.31) node[left,draw=Emerald, line width=0.20mm, fill=Emerald!10, align=left] {$m_f=0.530$} -- (axis cs:26.742, 0.530);
\draw[-{Circle[open, width=4pt, length=4pt]}, shorten >=-2pt,shorten <=0mm] (rel axis cs:0.83,0.125) node[left,draw=Lavender, line width=0.20mm, fill=Lavender!10, align=left] {$m_f=0.528$} -- (axis cs:27.887, 0.528); %add open, before width option inside Circle to have a not filled circle
\draw[-{Circle[open, width=4pt, length=4pt]}, shorten >=-2pt,shorten <=0mm] (rel axis cs:0.76,0.3) node[right,draw=Violet, line width=0.20mm, fill=Violet!10, align=left] {$m_f=0.525$} -- (axis cs:29.005, 0.525);
\end{axis}
\end{tikzpicture}
\caption{Mass $m$ as a function of time}
\end{figure}
I would like that the two plots should be positioned like 1 column and 2 rows, i.e. you should be able to read them downward, in addition they should have the same legend, positioned centered below, and they should keep their own heading. Here an example:
I'm not able to provide a MWE, because the data set is quite big. I just need the basic structure for this kind of group style, and then I would adapt my code to that structure. I hope someone can help me.
\addplot {rnd};
. Alternatively, read in a table with two or three rows.