具有多个 Y 轴的图表

具有多个 Y 轴的图表

如何创建一个具有多个 Y 轴(超过 2 个)且彼此堆叠且具有公共 X 轴的图形?

具有多个 y 轴的图表

参见附图。y 方向上的每个零代表新 y 轴的开始。

答案1

一个简单的例子groupplots

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
 group style={
  group size=1 by 4,  % sets number of columns and rows in groupplot array
  vertical sep=0pt,   % vertical distance between axes
 },
 axis y line=left, % y axis line on left side only
 xmin=0,xmax=10,   % set axis
 ymin=0,           % limits
 domain=1:9,       % domain, just for example
 width=10cm,       % width
 height=3cm,       % and height for each axis
 scale only axis,  % disregard labels and ticks for scaling
 no markers, 
 enlarge y limits=upper,
]

\nextgroupplot[
    ylabel=$y$,
    ylabel style={at={(rel axis cs:0,1)},above,rotate=-90}, %move ylabel a bit
    axis x line=none] % remove x-axis lines
 \addplot{x};

\nextgroupplot[axis x line=none]
 \addplot{-x + 10}; 

\nextgroupplot[axis x line=none]
 \addplot{x*x}; 

\nextgroupplot[
    axis x line=bottom, % only x axis line at bottom
    xlabel=$x$,
    xlabel style={at={(rel axis cs:1,0)},right}]
 \addplot+[samples=200] {abs(sin(x*180/pi))}; 

\end{groupplot}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容