Как можно перемещать график в \groupplot по горизонтали и вертикали?

Как можно перемещать график в \groupplot по горизонтали и вертикали?

Вот мой код:

\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}

Вот что у меня есть:

введите описание изображения здесь

Хочу переместить свой подсюжет выше. Как это можно сделать? Стоит ли мне использовать groupplotили есть какой-то другой способ сделать то, что я пытаюсь сделать?

решение1

По-моему, groupplotsони не предназначены для такого рода вещей. Я предлагаю использовать axisвместо этого две среды. Поместите a \coordinateна большую ось, используя систему координат rel axis csили axis cs, и поместите меньшую ось в эту координату.

В коде ниже вы увидите

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

в первой axisи в вариантах ко второй оси

at={(otheraxis)},

который помещает нижний левый угол в axis. otheraxisЭто позволяет вам легко перемещать меньшую ось, изменяя otheraxisкоординату.

\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}

Связанный контент