I am trying to align multiple tikzpictures. It gets complicated as I need the following figures to be aligned
- possibly two y-axis
- possibly legends
- captions
The pgfplots manual gives 3 possible methods (see "4.19.4 Alignment In Array Form (Subplots)")
tikzpictureenvironment inside of tablesmatrixinside oftikzpicturegroupplots
Currently I try option 1 as option 2 doesnot easily work together with legends. I have not tried option 3.
A minimal working example looks as follows
\documentclass[letterpaper,11pt,english]{article}
\usepackage[ascii]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subcaption}
\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15, small}
\begin{document}
example ref to fig \ref{fig1}
\begin{center}
\begin{tabular}{p{5cm}p{5cm}} % "p{5cm}": predefined width is need for captionof to work
\begin{tikzpicture}[baseline,trim axis left]
\begin{axis}[ylabel={yname}]
\addplot {x};
\end{axis}
\end{tikzpicture}
\captionof{figure}{\textbf{Confusion Matrix foobar}}
\label{fig1}
&
\begin{tikzpicture}[baseline,trim axis right]
\pgfplotsset{set layers, scale only axis, xmin=-5,xmax=5,width=5cm} % pgfplots' manual recommends those options: The Reference -> Axis Descriptions -> Two Ordinates
\begin{axis}[
ylabel={$f(x)=x^2$},
yticklabel pos=upper,
ylabel style={font=\Huge},
]
\addplot {x^2};
\label{x2}
\end{axis}
\begin{axis}[
ylabel={$f(x)=x^5$},
yticklabel pos=upper,
ylabel style={font=\Huge},
axis y line* = left,
ymode=log
]
% add potential to legend. only legend entries of last axis will be displayed.
\addlegendimage{/pgfplots/refstyle=plot_x2}\addlegendentry{$x^2$}
\addplot [red] {x^5};
\addlegendentry{$x^5$}
\end{axis}
\end{tikzpicture}
\
\begin{tikzpicture}[baseline,trim axis left]
\begin{axis}[xlabel=$x$,xlabel style={font=\Huge}]
\addplot {x^3};
\end{axis}
\end{tikzpicture}
&
\begin{tikzpicture}[baseline,trim axis right]
\begin{axis}[yticklabel pos=upper]
\addplot {x^4};
\end{axis}
\end{tikzpicture}
\
\end{tabular}
\end{center}
\end{document}


subfigorsubcaption? – Jes Feb 10 '21 at 21:52