pgfplots-删除图右侧和顶部的刻度标记

pgfplots-删除图右侧和顶部的刻度标记

您好,TEX/PGF/Tikz 社区,

我在使用 tikz 时遇到了麻烦,因为我想删除此图右侧和顶部的刻度标记

在此处输入图片描述

看到图片中丑陋的红色“圆圈”标记 :)。我知道可以删除两侧的刻度标记,但我只想删除一侧的刻度标记。有谁知道我该如何解决这个问题。我还想知道如何使其他刻度标记变小。

\documentclass[a4paper, 11 pt]{article}
\usepackage{pgfplots}
\usepackage{tikz}
    \newlength{\widthLarger}
    \setlength{\widthLarger}{10cm}
\pgfplotsset{compat=1.11,
    height=8cm,
    width=8cm}% most (standard) used width

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
        % Dimensions of plot
        % used default size determined in \pgfplotsset
        % Domain for values
        xmin = 1,
        xmax = 20,
        ymin = 0,
        ymax = 250,
        % Axis labeling
        xlabel = {Frequency [Hz]},
        ylabel = {Amplitude},
        title = {Test plot},
        %legend style = {at={(1.05,0.95)}, anchor = north east, cells = {anchor = west}}
        ]
        \addplot [red, mark = none, thick, smooth] coordinates{(1,20)(5,60)(7,90)(17,150)};
        \legend{Graph1}
        \end{axis}
    \end{tikzpicture}
\end{document}

答案1

您需要xtick pos=bottom,ytick pos=left,或者也可以使用tick pos=left,它们的作用相同。刻度的长度由参数定义tickwidth

代码输出

\documentclass[a4paper, 11 pt]{article}
\usepackage{pgfplots}

    \newlength{\widthLarger}
    \setlength{\widthLarger}{10cm}
\pgfplotsset{compat=1.11,
    height=8cm,
    width=8cm}% most (standard) used width

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
        % Dimensions of plot
        % used default size determined in \pgfplotsset
        % Domain for values
        xmin = 1,
        xmax = 20,
        ymin = 0,
        ymax = 250,
        % Axis labeling
        xlabel = {Frequency [Hz]},
        ylabel = {Amplitude},
        title = {Test plot},
        %legend style = {at={(1.05,0.95)}, anchor = north east, cells = {anchor = west}},
        % position of ticks
        xtick pos=bottom,
        ytick pos=left,
        % or alternatively
        %tick pos=left,
        % length of ticks
        tickwidth=1mm
        ]
        \addplot [red, mark = none, thick, smooth] coordinates{(1,20)(5,60)(7,90)(17,150)};
        \legend{Graph1}
        \end{axis}
    \end{tikzpicture}
\end{document}

相关内容