示例:具有两个 x 轴的 pgfplots groupplot

示例:具有两个 x 轴的 pgfplots groupplot

我想分享我的结果,groupplot 中有两个不同的 x 轴。一个轴是能量,另一个是相应的波长。到目前为止,这是我的工作解决方案,但也许有人可以改进代码?!

\documentclass[margin=2pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\pgfplotsset{grid style={dashed,gray}}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={columns=3,rows=4,horizontal sep=2cm},]
\nextgroupplot[axis y line*=left,
               axis x line*=bottom,
               scale only axis,
               xlabel={\textit{Energy} in eV},
               xmin=1,
               xmax=2,] % 1
\addplot[blue] coordinates {(1,2) (2,0)};
\nextgroupplot[at=(group c1r1.west), 
               axis y line*=right,
               axis x line*=top,
               scale only axis,
               x dir=reverse,
               xmin=620,
               xmax=1240,
               xlabel={\textit{Wavelength} in nm},] % 1, 2nd axis
\addplot[opacity=0] coordinates {(1240,0) (620,2)};
\nextgroupplot[axis y line*=right,
               axis x line*=top,
               scale only axis,       
               x dir=reverse,
               xlabel={\textit{Energy} in eV},
               xmin=1,
               xmax=2,] % 2, 2nd axis
\addplot[red] coordinates {(1,2) (2,0)};
\nextgroupplot[at=(group c3r1.north),
              axis y line*=left,
              axis x line*=bottom, 
              scale only axis,
              xmin=620,
              xmax=1240,
              xlabel={\textit{Wavelength} in nm},]
\addplot[opacity=0] coordinates {(1240,0) (620,2)};
\end{groupplot}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容