隐藏函数域之外的 x 轴部分

隐藏函数域之外的 x 轴部分

我制作了以下图表:

在此处输入图片描述

我如何“隐藏” x 轴大于 2pi 的部分?我认为现在那条悬挂的黑线看起来相当丑陋。

\begin{tikzpicture}
  \begin{axis}[
      axis lines = center,
      axis line style = {-},
      xlabel = $$,
      ylabel = $$,
      xmin = 0,
      xmax = 2*pi+1.1,
      xtick = {0, 1.5708, 3.1416, 4.7124, 6.2832},
      xticklabels = {$0$, $\frac\pi2$, $\pi$, $\frac{3\pi}2$, $2\pi$},
      ymin = -1.01,
      ymax = 1.01,
      ytick = {-1,0,1},
      height = 10em,
      width = 30em,
    ]
    \addplot [
      domain=0:2*pi,
      samples=100,
      name path=f,
    ]
    {sin(deg(x))*cos(deg(2*x))} node[pos=1.04,font=\small] {$\sin(x)\cos(2x)$};
    \path[name path=axis] (axis cs:0,0) -- (axis cs:1,0);
    \addplot [
      fill=gray,
      fill opacity=0.05
    ]
    fill between[
      of=f and axis,
    ];
  \end{axis}
\end{tikzpicture}

答案1

您可以使用xmax=2*\piclip=false

在此处输入图片描述

代码:

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
      axis lines = center,
      axis line style = {-},
      %xlabel = $$,
      %ylabel = $$,
      xmin = 0,
      xmax = 2*pi,% <- changed
      clip = false,% <- added
      xtick = {0, 1.5708, 3.1416, 4.7124, 6.2832},
      xticklabels = {$0$, $\frac\pi2$, $\pi$, $\frac{3\pi}2$, $2\pi$},
      ymin = -1.01,
      ymax = 1.01,
      ytick = {-1,0,1},
      height = 10em,
      width = 30em,
    ]
    \addplot [
      domain=0:2*pi,
      samples=100,
      name path=f,
    ]
    {sin(deg(x))*cos(deg(2*x))} node[pos=1.04,font=\small] {$\sin(x)\cos(2x)$};
    \path[name path=axis] (axis cs:0,0) -- (axis cs:1,0);
    \addplot [
      fill=gray,
      fill opacity=0.05
    ]
    fill between[
      of=f and axis,
    ];
  \end{axis}
\end{tikzpicture}
\end{document}

相关内容