图未使用 pgfplots 的 \nextgroupplot 和不连续性绘制?

图未使用 pgfplots 的 \nextgroupplot 和不连续性绘制?

我正在努力使用 pgfplots 的多轴不连续性,等等pgfplots 中的轴断裂,我制作了这个 MWE:

\documentclass{article}
\usepackage{calc} %\widthof

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{adjustbox}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group name=my fancy plots,
    group size=2 by 1,
    yticklabels at=edge left,
    %xticklabels at=edge bottom,
    %vertical sep=0pt,
    horizontal sep=0pt,
  },
%   width=8.5cm,
  height=6cm,
  ymin=-6, ymax=6
]

\nextgroupplot[
  xmin=0,xmax=5,
  xtick={0,5,10},
  axis y line=left,
  %axis x discontinuity=parallel, % disc. is at start, so avoid for first
  axis x line=bottom,
  x axis line style=-, % switch off the axis arrow tips,
  %width=4.5cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {x*0};

\nextgroupplot[
  xmin=45,xmax=80,
  axis y line=none,
  xtick={60,80},
  axis x discontinuity=parallel,
  axis x line=bottom,
  %width=2.0cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {0*x};

\end{groupplot}

\end{tikzpicture}
\end{center}
\end{document}

事实证明,我得到的是这样的:

测试51.png

...也就是说,该函数仅在第一个“子”图中绘制,但没有在第二个“子”图中绘制?!

我哪里做错了,以及如何才能让该函数完整地绘制出来?

答案1

您必须将domain键添加到您的组图中,以定义应在哪个范围内绘制函数。如果在选项中设置了此键\begin{groupplot},则您不必使用该sample键,以便在图的两个部分中获得相同的标记密度。当然您也可以使用该no markes键。

应用于你的 MWE 将会得到:

\documentclass{article}
\usepackage{calc} %\widthof

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{adjustbox}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group name=my fancy plots,
    group size=2 by 1,
    yticklabels at=edge left,
    %xticklabels at=edge bottom,
    %vertical sep=0pt,
    horizontal sep=0pt,
  },
%   width=8.5cm,
  height=6cm,
  ymin=-6, ymax=6,
  domain=0:80,
]

\nextgroupplot[
  xmin=0,xmax=5,
  xtick={0,5,10},
  axis y line=left,
  %axis x discontinuity=parallel, % disc. is at start, so avoid for first
  axis x line=bottom,
  x axis line style=-, % switch off the axis arrow tips,
  %width=4.5cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {0*x};

\nextgroupplot[
  xmin=45,xmax=80,
  axis y line=none,
  xtick={60,80},
  axis x discontinuity=parallel,
  axis x line=bottom,
  %width=2.0cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {0*x};

\end{groupplot}

\end{tikzpicture}
\end{center}
\end{document}

相关内容