\newsavebox{\legend}
\savebox{\legend}{
  \begin{tikzpicture}[font=\small]
    \matrix [%
    matrix of nodes,%
    ampersand replacement=\&,% to use inside a savebox
    nodes={anchor=west, align=left, inner sep=1pt},%
    column sep=1ex,%
    row sep=0ex,%
    ] (legend)
    {
      \draw[tab-blue] plot[mark=*] coordinates {(0,0)};
      \& \node[align=left, anchor=west, tab-blue, inner sep=1pt]{Nested 1\textsuperscript{st}-\\ order AD};
      \\[0.5ex]
      \draw[tab-orange] plot[mark=triangle*, rotate=270] coordinates {(0,0)};
      \& \node[align=left, anchor=west, tab-orange, inner sep=1pt]{Vanilla Tay-\!\\ lor mode};
      \\[0.5ex]
      \draw[tab-green] plot[mark=triangle*, rotate=90] coordinates {(0,0)};
      \& \node[align=left, anchor=west, tab-green, inner sep=1pt]{Forward\\ Laplacian};
      \\
    };
  \end{tikzpicture}
}

\begin{tikzpicture}
  \node (image) [inner sep=0pt] {% [trim={left bottom right top},clip]
    \includegraphics[trim={0 4cm 0 0},clip]{jet/exp/exp04_jax_benchmark/figures/architecture_tanh_mlp_768_768_512_512_1_device_cuda_dim_50_name_jax_laplacian_vary_batch_size.pdf}};
  \node (xaxis) [inner sep=0pt, anchor=north] at (image.south) {% [trim={left bottom right top},clip]
    \includegraphics[trim={0 0 0 6.4cm},clip]{jet/exp/exp04_jax_benchmark/figures/architecture_tanh_mlp_768_768_512_512_1_device_cuda_dim_50_name_jax_laplacian_vary_batch_size.pdf}};

  \node[rectangle, draw=gray, rounded corners, inner sep=-1pt, anchor=north west, xshift=1.35cm, fill=white, fill opacity=0.8, text opacity=1.0] at (image.north west) {\usebox{\legend}};
\end{tikzpicture}

%%% Local Variables:
%%% mode: LaTeX
%%% TeX-master: "../main"
%%% End:
