删除两个轴上的垂直线和水平线(tikzpicture)

删除两个轴上的垂直线和水平线(tikzpicture)

我有下图:

在此处输入图片描述

我希望能够删除轴上的所有条纹或线条,我用黑色将其括起来。这是我的代码,非常感谢您的帮助。

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\usepackage[margin = 0.9in]{geometry}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            height=5.5cm, width=0.8*\textwidth,
            axis lines=middle,
            %grid, grid style = {dashed},
            xlabel=$s$, xlabel style={anchor=west},
            ylabel style={anchor=south},
            xmin=-4, xmax=4,
            ymin=-3,  ymax=3,
            xticklabels=none, yticklabels=none,
            ]
            \addplot [
            domain=-3.8:3.8, 
            samples=100, 
            thick, smooth,
            ] {sin(deg(3*x))};
        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

答案1

像这样:

在此处输入图片描述

xticklabels=none, yticklabels=none,你应该写而不是xtick=\empty, ytick=\empty。因此,完整的 MWE 应该是:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\usepackage[margin = 0.9in]{geometry}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            height=5.5cm, width=0.8*\textwidth,
            axis lines=middle,
            xlabel=$s$, xlabel style={anchor=west},
            ylabel style={anchor=south},
            xmin=-4,    xmax=4,
            ymin=-2,    ymax=2,
            xtick=\empty, ytick=\empty  % <---
            ]
            \addplot [
            domain=-3.8:3.8,
            samples=100,
            thick, smooth,
            ] {sin(deg(3*x))};
        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

答案2

只需添加ticks=none到您的代码中:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}

\usepackage[margin = 0.9in]{geometry}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

\begin{figure}[H]
    \centering
    \begin{tikzpicture}
        \begin{axis}[
            height=5.5cm, width=0.8*\textwidth,
            axis lines=middle,
            %grid, grid style = {dashed},
            xlabel=$s$, xlabel style={anchor=west},
            ylabel style={anchor=south},
            xmin=-4, xmax=4,
            ymin=-3,  ymax=3,
            xticklabels=none, yticklabels=none,
            ticks=none
            ]
            \addplot [
            domain=-3.8:3.8, 
            samples=100, 
            thick, smooth,
            ] {sin(deg(3*x))};
        \end{axis}
    \end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

相关内容