[Tex/LaTex] Tikz Axis with colormap bounding box does not align with other bounding boxes

horizontal alignmentpgfplotstikz-pgf

My last question here was concerning tikz-axis aligned with centered other pictures. I received a very good answer. This question is similar but extends the question by a colormap as in the given example.

I want to have combined tikz-pgf-Graphs like the one shown below to be aligned at the main graph (in this case, the left one). I am using an external plot as described in the pgfplot-Manual in Chapter "4.2.8 Using External Graphics as Plot Sources". For simplicity I removed the pictures in my minimal example.

I my last post, I learned, that I can use "trim axis left, trim axis right" to have the graph aligned with other centered pictures. Of course, this does not work with a colormap as in my example. I have to use the external created colormap, because the tikz-version produces too large files because of to my points.

How do I reduce the bounding box to the left plot? By the way, is this the correct way for positioning this, or what do you recommend?

Example:

\documentclass{scrartcl} % Dokumentenklasse
\usepackage[decimalsymbol=comma]{siunitx} % SI-Einheiten einheitlich setzen

\usepackage{pgfplots} % Import der Plots aus Matlab
\usepackage{tikz} % Import der Plots aus Matlab
\usetikzlibrary{plotmarks} % Import der Plots aus Matlab

\newlength\fheight % Plots aus Matlab immer gleich gross
\newlength\fwidth % Plots aus Matlab immer gleich gross
\setlength\fheight{6cm} % Plots aus Matlab immer gleich gross
\setlength\fwidth{8cm} % Plots aus Matlab immer gleich gross

\pgfplotsset{ % Komma statt Punkt als Dezimaltrennzeichen
  x tick label style={/pgf/number format/use comma},
  y tick label style={/pgf/number format/use comma}}

\listfiles

\begin{document}
My pgf version is: \pgfversion 

\begin{figure}[!htb]
\begin{center}
\begin{tikzpicture}[]
\begin{axis}[
name=plot1,
scale only axis,
width=\fwidth,
height=\fheight,
xmin=0, xmax=2,
ymin=0, ymax=2,
xlabel={$x/\SI{}{\micro\meter}$},
ylabel={$y/\SI{}{\micro\meter}$},
axis on top]
% \addplot graphics [xmin=0, xmax=22,
% ymin=0, ymax=2] {../versuche/b_v610/step36_ende/ende_afm/detail_afm.eps};
\end{axis}
\hspace{10mm}

\begin{axis}[
axis on top,
at=(plot1.right of south east), anchor=left of south west,
width=0.0675676\fwidth, height=1\fheight,
scale only axis,
xmin=0, xmax=1,
ymin=-30, ymax=50,
xtick=\empty, yticklabel pos=left,
ylabel={$h(x,y)/\SI{}{\nano\meter}$}] 
% \addplot graphics [xmin=0, xmax=1, ymin=-30, ymax=50]
% {../versuche/b_v610/step36_ende/ende_afm/detail_afm-colorbar1.eps};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}

\begin{figure}[!htb]
\begin{center}
\begin{tikzpicture}
\begin{axis}[
name=plot1,
scale only axis,
width=\fwidth,
height=\fheight,
xmin=0, xmax=5,
ymin=0, ymax=5,
xlabel={$x$},
ylabel={$\sum_i x^2$},
axis on top]
% \addplot graphics [xmin=0, xmax=22,
% ymin=0, ymax=2] {../versuche/b_v610/step36_ende/ende_afm/detail_afm.eps};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}

\end{document}

Best Answer

You can still make use of the trim feature of TikZ: trim axis left is just a shorthand for trim left=(current axis.west). Since you can name your axes, you can specify which axis to use for the trimming. In your case, you can trim the upper tikzpicture using trim left=(plot1.west), name the small side plot plot2, and trim the lower tikzpicture using trim left=(plot1.west),trim right=(plot2.east). In this case, you're adding space on the right-hand side of the lower plot, so it appears to have the same width as the two upper plots.

enter image description here

\documentclass{scrartcl} % Dokumentenklasse
\usepackage[decimalsymbol=comma]{siunitx} % SI-Einheiten einheitlich setzen

\usepackage{pgfplots} % Import der Plots aus Matlab
\usepackage{tikz} % Import der Plots aus Matlab
\usetikzlibrary{plotmarks} % Import der Plots aus Matlab

\newlength\fheight % Plots aus Matlab immer gleich gross
\newlength\fwidth % Plots aus Matlab immer gleich gross
\setlength\fheight{6cm} % Plots aus Matlab immer gleich gross
\setlength\fwidth{8cm} % Plots aus Matlab immer gleich gross

\pgfplotsset{ % Komma statt Punkt als Dezimaltrennzeichen
  x tick label style={/pgf/number format/use comma},
  y tick label style={/pgf/number format/use comma}}

\listfiles

\begin{document}
My pgf version is: \pgfversion 

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[trim left=(plot1.west)]
\begin{axis}[
name=plot1,
scale only axis,
width=\fwidth,
height=\fheight,
xmin=0, xmax=2,
ymin=0, ymax=2,
xlabel={$x/\SI{}{\micro\meter}$},
ylabel={$y/\SI{}{\micro\meter}$},
axis on top]
% \addplot graphics [xmin=0, xmax=22,
% ymin=0, ymax=2] {../versuche/b_v610/step36_ende/ende_afm/detail_afm.eps};
\end{axis}
\hspace{10mm}

\begin{axis}[
name=plot2,
axis on top,
at=(plot1.right of south east), anchor=left of south west,
width=0.0675676\fwidth, height=1\fheight,
scale only axis,
xmin=0, xmax=1,
ymin=-30, ymax=50,
xtick=\empty, yticklabel pos=left,
ylabel={$h(x,y)/\SI{}{\nano\meter}$}] 
% \addplot graphics [xmin=0, xmax=1, ymin=-30, ymax=50]
% {../versuche/b_v610/step36_ende/ende_afm/detail_afm-colorbar1.eps};
\end{axis}
\end{tikzpicture}
\end{figure}

\begin{figure}[!htb]
\centering
\begin{tikzpicture}[trim left=(plot1.south west),trim right=(plot2.south east)]
\begin{axis}[
name=plot1,
scale only axis,
width=\fwidth,
height=\fheight,
xmin=0, xmax=5,
ymin=0, ymax=5,
xlabel={$x$},
ylabel={$\sum_i x^2$},
axis on top]
% \addplot graphics [xmin=0, xmax=22,
% ymin=0, ymax=2] {../versuche/b_v610/step36_ende/ende_afm/detail_afm.eps};
\end{axis}
\end{tikzpicture}
\end{figure}

\end{document}