pgfplot 中的自定义高亮线条

pgfplot 中的自定义高亮线条

我有以下 pgfplot TeX 代码:

\begin{tikzpicture}
                \begin{axis}[ 
                xtick={
                    5, 10
                },
                xticklabels={
                    $x$, $2x$
                },
                ytick={
                    -0.60,  0,  0.6
                },
                yticklabels={$-I(x)/2x$ , $0$,  $I(x)/2x$
                },
                axis x line=center,
                axis y line=left,
                ymin=-1.2, ymax=1.2,
                xmin=4.5, xmax=10.5,
                xlabel= \footnotesize $y$,  
                ylabel= \footnotesize $g(y)$
                ] 
                %\addplot[domain=5:10,samples = 500] {2*sin(deg(x*cos(deg(x))))/sqrt(x)}; 
                %funcion sin(x*cosx)/sqrt(x)
                \addplot[domain=5:10,samples = 500] {7*sin(deg(2.5*x))*cos(deg(x))/x}; 
                \draw[dashed] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0.6) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0.6);
                \draw[dashed] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},-0.6) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},-0.6);

                \draw[very thick] (axis cs:5.37,0) -- (axis cs:6.05,0);
                \draw[dotted] (axis cs: 5.37,0.6) -- (axis cs: 5.37,0);
                \draw[dotted] (axis cs: 6.05,0.6) -- (axis cs: 6.05,0);

                \draw[ultra thick] (axis cs:6.53,0) -- (axis cs:7.10,0);
                \draw[dotted] (axis cs: 6.53,-0.6) -- (axis cs: 6.53,0);
                \draw[dotted] (axis cs: 7.10,-0.6) -- (axis cs: 7.10,0);

                \draw[very thick] (axis cs:9.18,0) -- (axis cs:9.64,0);
                \draw[dotted] (axis cs: 9.18,0.6) -- (axis cs: 9.18,0);
                \draw[dotted] (axis cs: 9.64,0.6) -- (axis cs: 9.64,0);
                \end{axis}
                \end{tikzpicture}

此代码生成某个函数的图形,并通过在这些间隔上绘制一条粗线来突出显示 x 轴的 3 个间隔。我想知道是否还有其他类型的突出显示,例如此图片第一个间隔中显示的突出显示(使用 paint 修改):在此处输入图片描述

这样做的原因是,我稍后会突出显示其他间隔,这些间隔将与原始间隔重叠,因此我需要让两者都清晰可见。提前谢谢您。

答案1

ultra thick您可以绘制一个矩形,然后使用 中的图案填充它,而不必绘制一条线\usetikzlibrary{patterns}

可用的模式有:horizontal lines,,,,,,,,,,,,。vertical lines​​​​​​north east linesnorth west linesgridcrosshatchdotscrosshatch dotsfivepointed starssixpointed starsbrickscheckerboard

\documentclass[tikz,border=2mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns}

\begin{document}
    \begin{tikzpicture}

        \begin{axis}[   xtick       = {5, 10},
                        xticklabels = {$x$, $2x$},
                        ytick       = {-0.60,  0,  0.6},
                        yticklabels = {$-I(x)/2x$ , $0$,  $I(x)/2x$},
                        axis x line = center,
                        axis y line = left,
                        ymin        = -1.2,
                        ymax        = 1.2,
                        xmin        = 4.5,
                        xmax        = 10.5,
                        xlabel      = \footnotesize $y$,
                        ylabel      = \footnotesize $g(y)$
                    ]

            \addplot[domain=5:10,samples = 500] {7*sin(deg(2.5*x))*cos(deg(x))/x};

            \draw[dashed] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},0.6) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},0.6);
            \draw[dashed] (axis cs:\pgfkeysvalueof{/pgfplots/xmin},-0.6) -- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},-0.6);

            \fill[pattern=north west lines, pattern color = blue] (axis cs:5.37,-.02) -- (axis cs:5.37,.02) -- (axis cs:6.05,.02) -- (axis cs:6.05,-.02) -- cycle;
            \draw[dotted] (axis cs: 5.37,0.6) -- (axis cs: 5.37,0);
            \draw[dotted] (axis cs: 6.05,0.6) -- (axis cs: 6.05,0);

            \fill[pattern=crosshatch, pattern color = green] (axis cs:6.53,-.02) -- (axis cs:6.53,.02) -- (axis cs:7.10,.02) -- (axis cs:7.10,-.02) -- cycle;
            \draw[dotted] (axis cs: 6.53,-0.6) -- (axis cs: 6.53,0);
            \draw[dotted] (axis cs: 7.10,-0.6) -- (axis cs: 7.10,0);

            \fill[pattern=north east lines, pattern color = red] (axis cs:9.18,-.02) -- (axis cs:9.18,.02) -- (axis cs:9.64,.02) -- (axis cs:9.64,-.02) -- cycle;
            \draw[dotted] (axis cs: 9.18,0.6) -- (axis cs: 9.18,0);
            \draw[dotted] (axis cs: 9.64,0.6) -- (axis cs: 9.64,0);
        \end{axis}

    \end{tikzpicture}
\end{document}

在此处输入图片描述

重叠示例:

\fill[pattern=north west lines, pattern color = blue] (axis cs:5.37,-.03) -- (axis cs:5.37,.03) -- (axis cs:7.10,.03) -- (axis cs:7.10,-.03) -- cycle;
\draw[dotted] (axis cs: 5.37,0.6) -- (axis cs: 5.37,0);
\draw[dotted] (axis cs: 6.05,0.6) -- (axis cs: 6.05,0);

\fill[pattern=north east lines, pattern color = red] (axis cs:6.05,.03) -- (axis cs:6.05,-.03) -- (axis cs:6.53,-.03) -- (axis cs:6.53,.03) -- cycle;
\draw[dotted] (axis cs: 6.53,-0.6) -- (axis cs: 6.53,0);
\draw[dotted] (axis cs: 7.10,-0.6) -- (axis cs: 7.10,0);

在此处输入图片描述

图案并不是唯一的解决方案。如果您想使用色块,可以尝试以下设置opacity以显示漂亮的重叠:

\fill[color=blue, opacity=.5] (axis cs:5.37,-.03) -- (axis cs:5.37,.03) -- (axis cs:6.53,.03) -- (axis cs:6.53,-.03) -- cycle;
\fill[color=red, opacity=.5] (axis cs:6.05,.03) -- (axis cs:6.05,-.03) -- (axis cs:7.10,-.03) -- (axis cs:7.10,.03) -- cycle;

在此处输入图片描述

相关内容