如何在 pgfplots 中绘制两个相互叠加的折线图

如何在 pgfplots 中绘制两个相互叠加的折线图

我需要制作一张由两到三个不同图组成的图表,每个图共享相同的内容x-axis,但具有不同的内容y-axes,一个在另一个之上。有点像这样

在此处输入图片描述

除了我实际上不需要那一秒x-axis(尽管如果它像一两行添加,那也很好知道)。

这是我的代码,其中分成了三个不同的图:

\documentclass[reprint, amsmath,amssymb, aps,]{revtex4-1}

\usepackage{pgfplots}% Make nice looking plot
\pgfplotsset{compat = newest}% The default is really old: let's use newer settings

\begin{document}

    \begin{figure}[h]% CaCO3 (Aragonite)
        \begin{tikzpicture}
        \begin{axis}[title = CaCO$_3$ (Aragonite),
        xlabel = Raman shifts\,/\,cm$\text{}^{-1}$,
        xmax = 2050,
        xmin = 200,
        ylabel = Intensity Counts,
        ymax = 6000,
        ymin = 0]

        \addplot[black, % Plotting the data
        no marks]
        table[x=xram,y=yram] {RamanData_Aragonite.dat} ;
        \end{axis}
        \end{tikzpicture}
        \caption{Caption goes here}
    \end{figure}

    \begin{figure}[h]% Solid CaCO3
        \begin{tikzpicture}
        \begin{axis}[title = CaCO$_3$ (Solid),
        xlabel = Raman shifts\,/\,cm$\text{}^{-1}$,
        xmax = 2050,
        xmin = 200,
        ylabel = Intensity Counts,
        ymax = 60000,
        ymin = 0]

        \addplot[black, % Plotting the data
        no marks]
        table[x=xram,y=yram] {RamanData_CaCO3_Solid.dat} ;
        \end{axis}
        \end{tikzpicture}
        \caption{Caption goes here}
    \end{figure}

    \begin{figure}[h]% CaCO3
        \begin{tikzpicture}
        \begin{axis}[title = CaCO$_3$,
        xlabel = Raman shifts\,/\,cm$\text{}^{-1}$,
        xmax = 2050,
        xmin = 200,
        ylabel = Intensity Counts,
        ymax = 15000,
        ymin = 0]

        \addplot[black, % Plotting the data
        no marks]
        table[x=xram,y=yram] {RamanData_CaCO3.dat} ;
        \end{axis}
        \end{tikzpicture}
        \caption{Caption goes here}
    \end{figure}

\end{document}

答案1

您可以使用groupplots库并调整轴线。示例:

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{pgfplots}% Make nice looking plot
\pgfplotsset{compat = 1.11}% The default is really old: let's use newer settings
\usepgfplotslibrary{groupplots}
\begin{document}
    \begin{figure}[h]% CaCO3 (Aragonite)
        \centering
        \begin{tikzpicture}
        \begin{groupplot}[group style={group size=1 by 2,
            horizontal sep=0pt,
            vertical sep=1cm},
            height=6cm,width=6cm,
        ]
        \nextgroupplot[
          axis x line=none,
          axis y line=left,
          title = CaCO$_3$ (Solid),
          %xlabel = Raman shifts\,/\,cm$\text{}^{-1}$,
          xmax = 2050,
          xmin = 200,
          ylabel = Intensity Counts,
          ymax = 6000,
          ymin = 0
        ]
        \addplot[black, % Plotting the data
            no marks] {rand};
        %table[x=xram,y=yram] {RamanData_Aragonite.dat} ;


        \nextgroupplot[
            axis x line=bottom,
            axis y line=left,
            title = CaCO$_3$ (Aragonite),
            xlabel = Raman shifts\,/\,cm$\text{}^{-1}$,
            xmax = 2050,
            xmin = 200,
            ylabel = Intensity Counts second,
            ymax = 6000,
            ymin = 0
        ]
        \addplot[black, % Plotting the data
            no marks] {rand};
            %table[x=xram,y=yram] {RamanData_CaCO3_Solid.dat} ;
        \end{groupplot}
        \end{tikzpicture}
        \caption{Caption goes here}
    \end{figure}

\end{document}

在此处输入图片描述

相关内容