Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
Do the two large plots belong together, i.e. could they go into the same figure environment with only one main caption (but possible different subcaptions)? Could all the plots go into the same tikzpicture (same main caption, difficult to get different subcaptions)? –  Jake Aug 31 '11 at 10:06
    
The large plots are spread all over my long document. The small plot is just a colorbar, which is like a legend for the first large plot. –  Lukas Aug 31 '11 at 19:10
add comment

3 Answers

up vote 1 down vote accepted

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}
share|improve this answer
    
Hello Jake. This was not exactly my intention but your answer gave me the right hint: Using trim ...=(...) instead of trim axis ... solved my problem (see my answer). Thank you. –  Lukas Aug 31 '11 at 11:36
add comment

If the two plots must go together, you can enclose them in a tabular:

\begin{figure}[!htb]
\centering
\begin{tabular}{@{}l@{}}
\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={$\vphantom{\sum}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 of first row
\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{tabular}
\end{figure}

Notice the \vphantom{\sum} in the ylabel for the first diagram, to ensure correct alignment.

share|improve this answer
    
Thank you for your answer. This is a good idea, if for example 4 plots have to go together. Tikzpicture1 and Tikzpicture2 are somewhere in a long document but should be aligned anyway. I found the solution with Jakes answer (see over there). –  Lukas Aug 31 '11 at 11:34
add comment

This is what i found out with your answers:

The problem was, that

trim axis left, trim axis right

behaves like

trim right=(plot2.east), trim left=(plot2.west)

instead of trimming the main plot.

I named the colorbar "plot2" and used the following trim commands:

trim right=(plot1.east), trim left=(plot1.west)

example with text and aligned plots

share|improve this answer
    
I think you mean plot1.east and plot1.west in your final code (instead of plot2...), right? –  Jake Sep 1 '11 at 12:20
    
Correct. I will edit it. Thank you. –  Lukas Sep 2 '11 at 17:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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