Wie kann das Diagramm in \groupplot horizontal und vertikal verschoben werden?

Wie kann das Diagramm in \groupplot horizontal und vertikal verschoben werden?

Dies ist mein Code:

\documentclass[tikz,12pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{mathptmx}    
\usetikzlibrary{pgfplots.groupplots}
\usepackage{pgfplots}
\pgfplotsset{width=12cm,compat=1.9}

\usepackage{filecontents}
\begin{filecontents}{1.csv}
400 0.02
450 0.03
500 0.035
550 0.08
600 0.1
650 0.05
700 0.15
750 0.12
800 0.02
850 0.05
900 0.1
\end{filecontents}
\begin{filecontents}{2.csv}
1   0.02
2   0.03
3 0.035
4   0.08
5   0.1
6 0.05
7   0.15
8 0.12
9   0.02
10  0.05
11  0.1
\end{filecontents}

\begin{document}
\pgfplotsset{every axis/.append style={
line width=.5 pt,
tick style={line width=.6pt}}}
\begin{tikzpicture}
\begin{groupplot}[group style={
        group size=2 by 1,
        vertical sep=-10cm,
        horizontal sep=-8.5cm,
    },]    
\nextgroupplot[
height=10cm,
xmin=400,
ymax=0.2,
enlarge x limits=.0,
enlarge y limits=.02,
ylabel={Absorption, A.U.},
xlabel={Wavelength, nm},
minor x tick num=4,
minor y tick num=4,
tick label style={/pgf/number format/fixed},
%xtick={200, 220, ...,360},
legend style={legend pos=north west,legend cell align=left,font=\tiny,draw=none,text height=0.1em},
]

\addplot[green] table [x index=0,y index=1] {1.csv};

\nextgroupplot[
font=\tiny,
height=5cm,
width=4cm,
ymax=0.12,
enlarge x limits=.0,
enlarge y limits=.02,
ylabel={Absorption at 740\,nm, A.U.},
xlabel={pH},
x label style={at={(axis description cs:0.5,-.05)},anchor=north},
y label style={at={(axis description cs:-0.2,.5)},anchor=south},
tick label style={/pgf/number format/fixed},
minor x tick num=4,
minor y tick num=4,
%xtick={200, 220, ...,360},
legend style={legend pos=north west,legend cell align=left,font=\tiny,draw=none,text height=0.1em},
]
\addplot[black,mark=*,dashed,line width=0.5pt] table [x index=0,y index=1] {2.csv};
\end{groupplot}
\end{tikzpicture}

\end{document}

Das ist, was ich habe:

Bildbeschreibung hier eingeben

Ich möchte meine Nebenhandlung nach oben verschieben. Wie könnte das gemacht werden? Soll ich verwenden groupplotoder gibt es eine andere Möglichkeit, das zu tun, was ich versuche?

Antwort1

Meiner Meinung nach groupplotssind sie nicht wirklich für solche Dinge gedacht. Ich schlage axisstattdessen vor, zwei Umgebungen zu verwenden. Platzieren Sie ein \coordinateauf der größeren Achse mithilfe des Koordinatensystems rel axis csoder und platzieren Sie die kleinere Achse an dieser Koordinate.axis cs

Im folgenden Code sehen Sie

\coordinate (otheraxis) at (rel axis cs:0.15,0.5);

in der ersten axisund in den Optionen zur zweiten Achse

at={(otheraxis)},

Dadurch wird die untere linke Ecke des axisbei platziert otheraxis. So können Sie die kleinere Achse einfach verschieben, indem Sie die otheraxisKoordinate ändern.

\documentclass[tikz,12pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{mathptmx}    
\usetikzlibrary{pgfplots.groupplots}
\usepackage{pgfplots}
\pgfplotsset{width=12cm,compat=1.9}

\usepackage{filecontents}
\begin{filecontents}{1.csv}
400 0.02
450 0.03
500 0.035
550 0.08
600 0.1
650 0.05
700 0.15
750 0.12
800 0.02
850 0.05
900 0.1
\end{filecontents}
\begin{filecontents}{2.csv}
1   0.02
2   0.03
3 0.035
4   0.08
5   0.1
6 0.05
7   0.15
8 0.12
9   0.02
10  0.05
11  0.1
\end{filecontents}

\begin{document}
\pgfplotsset{every axis/.append style={
line width=.5 pt,
tick style={line width=.6pt}}}

\begin{tikzpicture}
\begin{axis}[
height=10cm,
xmin=400,
ymax=0.2,
enlarge x limits=.0,
enlarge y limits=.02,
ylabel={Absorption, A.U.},
xlabel={Wavelength, nm},
minor x tick num=4,
minor y tick num=4,
tick label style={/pgf/number format/fixed},
%xtick={200, 220, ...,360},
legend style={legend pos=north west,legend cell align=left,font=\tiny,draw=none,text height=0.1em},
]

\addplot[green] table [x index=0,y index=1] {1.csv};

\coordinate (otheraxis) at (rel axis cs:0.15,0.5);
\fill [red] (otheraxis) circle[radius=3pt];
\end{axis}

\begin{axis}[
at={(otheraxis)},
font=\tiny,
height=5cm,
width=4cm,
ymax=0.12,
enlarge x limits=.0,
enlarge y limits=.02,
ylabel={Absorption at 740\,nm, A.U.},
xlabel={pH},
x label style={at={(axis description cs:0.5,-.05)},anchor=north},
y label style={at={(axis description cs:-0.2,.5)},anchor=south},
tick label style={/pgf/number format/fixed},
minor x tick num=4,
minor y tick num=4,
%xtick={200, 220, ...,360},
legend style={legend pos=north west,legend cell align=left,font=\tiny,draw=none,text height=0.1em},
]
\addplot[black,mark=*,dashed,line width=0.5pt] table [x index=0,y index=1] {2.csv};
\end{axis}
\end{tikzpicture}

\end{document}

verwandte Informationen