在 pgfplots 中将图片与 groupplot 垂直对齐

在 pgfplots 中将图片与 groupplot 垂直对齐

我正在尝试将图片与单个图中的 groupplot 对齐。即使我使用的是,valign=t命令也会给出。有什么想法可以做到这一点吗?这是我正在使用的代码:Package pgfkeys Error\usepackage{adjustbox}

\documentclass[12pt]{article}

\setlength{\oddsidemargin}{0in}  %left margin position, reference is one inch
\setlength{\textwidth}{6.5in}    %width of text=8.5-1in-1in for margin
\setlength{\topmargin}{-0.5in}    %reference is at 1.5in, -.5in gives a start of about 1in from top
\setlength{\textheight}{9in}     %length of text=11in-1in-1in (top and bot. marg.) 


\usepackage{amsmath,amssymb}
\usepackage{graphicx}% Include figure files
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
\usepackage[numbers,super,comma,sort&compress]{natbib}
\usepackage[labelfont=bf,font=sf,labelsep=period]{caption}
\usepackage[detect-all,load-configurations=si-abbr]{siunitx}

\sisetup{range-units=single,range-phrase=\,--\,,separate-uncertainty=true}


\usepackage{pgfplots}
\usepackage{pgfplotstable}%fitting functions
\usepackage{tikz}
\usetikzlibrary{tikzmark,patterns}
\usepackage{xcolor}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{fillbetween}
\usepackage{subfig}
\usepackage{geometry}
\usepackage{adjustbox}

\pgfkeys{/pgf/number format/.cd,1000 sep={}}
\definecolor{ao(english)}{rgb}{0.0, 0.5, 0.0}
\usepgfplotslibrary{colormaps}
\pgfplotsset{colormap={mygray}{gray(0.3cm)=(0.3); gray(0.9cm)=(0.9)}}

\usepackage[symbol]{footmisc}


\pgfplotsset{compat=1.15}
\pgfplotsset{label style={font=\large},
            tick label style={font=\large}}
             

\pgfplotsset{
% override style for non-boxed plots
    % which is the case for both sub-plots
    every non boxed x axis/.style={} 
}

\begin{document}


\begin{figure}[t!]
\raggedright
\begin{tikzpicture}[scale=1]
\begin{groupplot}[group style={group size=1 by 2,vertical sep=0pt}]

\nextgroupplot[enable tick line clipping=false,
    ymode=log,
    width=6cm,
    height=4.5cm,
    axis line style=thick,
    axis on top=true,
    x tick style={draw=none},
    axis x line=box,
    xmin=1,xmax=5,
    xticklabels={,,},
    y tick style={black,thick},
    y label style={at=(ticklabel cs:0),anchor=near ticklabel},
    ymin=2e8,ymax=10^10,
    ytick={10^9,10^10},
    axis y discontinuity=crunch,
    ytick pos=left,
    ytick align=outside,
    ylabel={resistance [\SI{}{\ohm}]},
]
    \addplot [red,very thick,y=y,x=x] table {
    x       y
    1       3e9
    5       3e9
    };


\nextgroupplot[enable tick line clipping=false,
    ymode=log,
    width=6cm,
    height=4.5cm,
    colormap name=mygray,
    axis line style=thick,
    axis x line=bottom,
    axis on top=true,
    x tick style={black,thick},
    x label style={at=(ticklabel cs:0.5),anchor=near ticklabel},
    xmin=1,xmax=5,
    xtick={1,2,...,5},
    xtick pos=bottom,
    xtick align=outside,
    xlabel={volume [\SI{}{\ml}]},
   y tick style={black,thick},
%    y label style={at=(ticklabel cs:0.5),anchor=near ticklabel},
    ymin=10^3,ymax=3e4,
    ytick={10^3,10^4},
    ytick pos=left,
    ytick align=outside,
%    ylabel={resistance [\SI{}{\ohm}]},
]
    \addplot [scatter,only marks,mark options={scale=1.8},y=y,x=x] table {
    x       y
    1       10200
    2       5730
    3       3610
    4       3030
    5       2790
    };


\end{groupplot}

\draw [white,fill=white] (0.04,-0.05) rectangle (4.39,0.05);

\end{tikzpicture}

\centering
\begin{tikzpicture}[valign=t,scale=0.5]
\includegraphics[width=0.5\textwidth]{DEAreal.jpeg}
\end{tikzpicture}
\end{figure}

\end{document}

在此处输入图片描述

答案1

您需要相应地定义图像的基线:

\documentclass[12pt]{article}

\setlength{\oddsidemargin}{0in}  %left margin position, reference is one inch
\setlength{\textwidth}{6.5in}    %width of text=8.5-1in-1in for margin
\setlength{\topmargin}{-0.5in}    %reference is at 1.5in, -.5in gives a start of about 1in from top
\setlength{\textheight}{9in}     %length of text=11in-1in-1in (top and bot. marg.)


\usepackage{amsmath,amssymb}
\usepackage[export]{adjustbox}  % also load graphicx
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
\usepackage[numbers,super,comma,sort&compress]{natbib}
\usepackage[labelfont=bf,font=sf,labelsep=period]{caption}
\usepackage[detect-all,load-configurations=si-abbr]{siunitx}

\sisetup{range-units=single,range-phrase=\,--\,,separate-uncertainty=true}


\usepackage{pgfplots}
\usepackage{pgfplotstable}%fitting functions
\usetikzlibrary{tikzmark,patterns}
\usepackage{xcolor}
\usepgfplotslibrary{groupplots}
\usepgfplotslibrary{fillbetween}
\usepackage{subfig}
\usepackage{geometry}

\pgfkeys{/pgf/number format/.cd,1000 sep={}}
\definecolor{ao(english)}{rgb}{0.0, 0.5, 0.0}
\usepgfplotslibrary{colormaps}
\pgfplotsset{colormap={mygray}{gray(0.3cm)=(0.3); gray(0.9cm)=(0.9)}}

\usepackage[symbol]{footmisc}


\pgfplotsset{compat=1.15}
\pgfplotsset{label style={font=\large},
            tick label style={font=\large}}


\pgfplotsset{
% override style for non-boxed plots
    % which is the case for both sub-plots
    every non boxed x axis/.style={}
}

\begin{document}


\begin{figure}[t!]
\centering
\begin{tikzpicture}[baseline={([yshift=-2ex]current bounding box.north)}]  % <---
\begin{groupplot}[group style={group size=1 by 2,vertical sep=0pt}]

\nextgroupplot[enable tick line clipping=false,
    ymode=log,
    width=6cm,
    height=4.5cm,
    axis line style=thick,
    axis on top=true,
    x tick style={draw=none},
    axis x line=box,
    xmin=1,xmax=5,
    xticklabels={,,},
    y tick style={black,thick},
    y label style={at=(ticklabel cs:0),anchor=near ticklabel},
    ymin=2e8,ymax=10^10,
    ytick={10^9,10^10},
    axis y discontinuity=crunch,
    ytick pos=left,
    ytick align=outside,
    ylabel={resistance [\SI{}{\ohm}]},
]
    \addplot [red,very thick,y=y,x=x] table {
    x       y
    1       3e9
    5       3e9
    };
\nextgroupplot[enable tick line clipping=false,
    ymode=log,
    width=6cm,
    height=4.5cm,
    colormap name=mygray,
    axis line style=thick,
    axis x line=bottom,
    axis on top=true,
    x tick style={black,thick},
    x label style={at=(ticklabel cs:0.5),anchor=near ticklabel},
    xmin=1,xmax=5,
    xtick={1,2,...,5},
    xtick pos=bottom,
    xtick align=outside,
    xlabel={volume [\SI{}{\ml}]},
   y tick style={black,thick},
%    y label style={at=(ticklabel cs:0.5),anchor=near ticklabel},
    ymin=10^3,ymax=3e4,
    ytick={10^3,10^4},
    ytick pos=left,
    ytick align=outside,
%    ylabel={resistance [\SI{}{\ohm}]},
]
    \addplot [scatter,only marks,mark options={scale=1.8},y=y,x=x] table {
    x       y
    1       10200
    2       5730
    3       3610
    4       3030
    5       2790
    };

\end{groupplot}
\draw [white,fill=white] (0.04,-0.05) rectangle (4.39,0.05);
\end{tikzpicture}
\qquad
\includegraphics[width=0.4\textwidth, valign=T]{example-image}%{DEAreal.jpeg} % <---
\end{figure}

\end{document}

在此处输入图片描述

相关内容