粗体刻度数字

粗体刻度数字

虽然有很多关于如何摆弄(拉丁语)刻度标签、刻度位置或刻度颜色的帖子,但我找不到任何关于如何更改刻度本身的长度和宽度的内容(无论是实际示例还是文档)。也许我只是没有找到正确的搜索短语。

无论如何,这个问题可能不需要 MWE,但为了提供一个简单的“演示答案”,这里有一个简单的图,我想将长度(从刻度线顶部到轴的距离)减少(比如说)50%,相对于默认长度。提前谢谢。

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
    \begin{axis}
      [width=190pt,axis x line=middle, axis y line=center, 
      tick align=outside,
      xmin=0.3,xmax=7.7,ymin=0.44,ymax=1.05,
      xlabel={\emph{x-axis label}},ylabel={\emph{y-axis label}},
      xtick={1,2,3,4,5,6,7},ytick={0.5,0.6,0.7,0.8,0.9,1.0},
      x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
      y label style={at={(axis description cs:-0.1,.5)},rotate=90,anchor=south},
      every tick/.style={black,semithick,height=1cm},
      ylabel style={yshift=0.2cm}, xlabel style={yshift=-0.2cm}]
        \addplot+[mark=none,smooth, thick]  plot coordinates {
            (1,1)
            (2,0.75)
            (3,0.666)
            (4,0.625)
            (5,0.6)
            (6,0.5833)
            (7,0.571)
        };
        \addplot [red, dashed, no markers, thick] coordinates {(0.3,0.5) (7.7,0.5)};
    \end{axis}
\end{tikzpicture}
\end{document}

答案1

major tick length刻度长度可以通过选项(或别名)配置。小刻度可以通过选项(或)tickwidth配置。在这种情况下,我们只有主刻度。默认值为,可以通过派生而来。我在“4.15.4 刻度微调”一节中找到了选项名称minor tick lengthsubtickwidth0.15cm\pgfkeysvalueof{/pgfplots/major tick length}手动的pgfplots

示例,将刻度长度设置为默认值的 50%:

\documentclass{article}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.12}

\begin{document}
\begin{tikzpicture}
    \pgfmathsetlengthmacro\MajorTickLength{
      \pgfkeysvalueof{/pgfplots/major tick length} * 0.5
    }
    \begin{axis}[ 
      width=190pt,
      axis x line=middle,
      axis y line=center,
      tick align=outside,
      xmin=0.3, 
      xmax=7.7, 
      ymin=0.44,
      ymax=1.05,
      xlabel={\emph{x-axis label}},
      ylabel={\emph{y-axis label}},
      xtick={1,2,3,4,5,6,7},
      ytick={0.5,0.6,0.7,0.8,0.9,1.0},
      x label style={
        at={(axis description cs:0.5,-0.1)},
        anchor=north,
      },
      y label style={
        at={(axis description cs:-0.1,.5)},
        rotate=90,   
        anchor=south,
      },
      major tick length=\MajorTickLength,
      every tick/.style={
        black,
        semithick,
      },
      ylabel style={yshift=0.2cm},
      xlabel style={yshift=-0.2cm}
    ]
        \addplot+[mark=none,smooth, thick]  plot coordinates {
            (1,1)     
            (2,0.75)  
            (3,0.666) 
            (4,0.625) 
            (5,0.6)   
            (6,0.5833)
            (7,0.571)
        };
        \addplot [red, dashed, no markers, thick] coordinates {(0.3,0.5)
        (7.7,0.5)};
    \end{axis}   
\end{tikzpicture}
\end{document}   

结果

粗体刻度数字

这是对 CroCo 的回答评论以及 Manuel Kuehner 博士的评论

可以通过选项设置粗体刻度数tick label style。由于刻度数默认在数学模式中设置(参见\axisdefaultticklabel),\boldmath因此会获得粗体刻度数。

Keytick label style附加到every tick/.style,因此以下更新的示例(使用pgfplots1.17)合并了两个键:

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

\begin{document}
\begin{tikzpicture}
    \pgfmathsetlengthmacro\MajorTickLength{
      \pgfkeysvalueof{/pgfplots/major tick length} * 0.5
    }
    \begin{axis}[
      width=190pt,
      axis x line=middle,
      axis y line=center,
      tick align=outside,
      xmin=0.3,
      xmax=7.7,
      ymin=0.44,
      ymax=1.05,
      xlabel={\emph{x-axis label}},
      ylabel={\emph{y-axis label}},
      xtick={1,2,3,4,5,6,7},
      ytick={0.5,0.6,0.7,0.8,0.9,1.0},
      x label style={
        at={(axis description cs:0.5,-0.1)},
        anchor=north,
      },
      y label style={
        at={(axis description cs:-0.1,.5)},
        rotate=90,
        anchor=south,
      },
      major tick length=\MajorTickLength,
      ylabel style={yshift=0.2cm},
      xlabel style={yshift=-0.2cm},
      tick label style={black, semithick, font=\boldmath},
    ]
        \addplot+[mark=none,smooth, thick]  plot coordinates {
            (1,1)
            (2,0.75)
            (3,0.666)
            (4,0.625)
            (5,0.6)
            (6,0.5833)
            (7,0.571)
        };
        \addplot [red, dashed, no markers, thick] coordinates {(0.3,0.5)
        (7.7,0.5)};
    \end{axis}
\end{tikzpicture}
\end{document}

以粗体数字显示的结果

相关内容