![如何在 pgfplots 中绘制两个相互叠加的折线图](https://linux22.com/image/305158/%E5%A6%82%E4%BD%95%E5%9C%A8%20pgfplots%20%E4%B8%AD%E7%BB%98%E5%88%B6%E4%B8%A4%E4%B8%AA%E7%9B%B8%E4%BA%92%E5%8F%A0%E5%8A%A0%E7%9A%84%E6%8A%98%E7%BA%BF%E5%9B%BE.png)
我需要制作一张由两到三个不同图组成的图表,每个图共享相同的内容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}