在组图中对齐公共轴标签

在组图中对齐公共轴标签

请参阅以下链接

组图的通用标签

我已经将这种方法应用于我的组图,效果很好,而且比其他解决方案简单得多。我遇到的唯一问题是我的 y 轴标签与轴有点偏移。(椭圆突出显示了额外的间隙)。不知道如何修复它。

Output

梅威瑟:

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{plot coordinates/math parser=false}
\usetikzlibrary{pgfplots.units}
\begin{document}
\sbox0{\includegraphics[width=4in]{example-image-a}}%
\sbox1{\includegraphics[width=4in]{example-image-a}}%
    \begin{tikzpicture}
        \begin{groupplot}[
            group style={
                group name=my plots,
                group size=1 by 2,
                xlabels at=edge bottom,
                xticklabels at=edge bottom,
                vertical sep=0pt
            },
            scale only axis, width={\wd0}, height={\ht0},
            ybar,
            footnotesize,
            width=5.4in,
            height=1in,  
            xlabel={Length($mm$)},
%           ylabel={Height($mm$)},
            xmin=0, xmax=10,
            ymin=0, ymax=0.6,
            xtick={0,1,...,10},
            xticklabels={0,1,...,10},
            ytick={0,0.2,...,0.6},
            yticklabels={0,0.2,0.4,0.6},
            tickpos=left,
            ytick align=outside,
            xtick align=outside
        ]
        \nextgroupplot
        \addplot graphics[xmin=0,ymin=0,xmax=10,ymax=0.6] {example-image-a};
        \nextgroupplot[ylabel=Height($mm$),
              every axis y label/.append style={at=(ticklabel cs:1.0)}]
        \addplot  graphics[xmin=0,ymin=0,xmax=10,ymax=0.6] {example-image-b};
        \end{groupplot}

    \end{tikzpicture}
\end{document}

答案1

enter image description here

在 \nextgroupplot 选项中使用 [ylabel shift= ??]:

\documentclass{standalone}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{plot coordinates/math parser=false}
\usetikzlibrary{pgfplots.units}
\begin{document}
\sbox0{\includegraphics[width=4in]{example-image-a}}%
\sbox1{\includegraphics[width=4in]{example-image-a}}%
    \begin{tikzpicture}
        \begin{groupplot}[
            group style={
                group name=my plots,
                group size=1 by 2,
                xlabels at=edge bottom,
                xticklabels at=edge bottom,
                vertical sep=0pt
            },
            scale only axis, width={\wd0}, height={\ht0},
            ybar,
            footnotesize,
            width=5.4in,
            height=1in,  
            xlabel={Length($mm$)},
%           ylabel={Height($mm$)},
            xmin=0, xmax=10,
            ymin=0, ymax=0.6,
            xtick={0,1,...,10},
            xticklabels={0,1,...,10},
            ytick={0,0.2,...,0.6},
            yticklabels={0,0.2,0.4,0.6},
            tickpos=left,
            ytick align=outside,
            xtick align=outside
        ]
        \nextgroupplot
        \addplot graphics[xmin=0,ymin=0,xmax=10,ymax=0.6] {example-image-a};
        \nextgroupplot[ylabel=Height($mm$),ylabel shift = -25 pt,
              every axis y label/.append style={at=(ticklabel cs:1.0)}]
        \addplot  graphics[xmin=0,ymin=0,xmax=10,ymax=0.6] {example-image-b};
        \end{groupplot}

    \end{tikzpicture}
\end{document}

相关内容