如何更改 pgfplots 中轴刻度标签的字体大小?

如何更改 pgfplots 中轴刻度标签的字体大小?

这个问题肯定以前有人问过,但是我找不到它,而且我在用户指南中搜索也无果。

我有以下图表:

% arara: pdflatex
% arara: pdflatex
% arara: open
\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{every axis/.append style={
                    axis x line=middle,    % put the x axis in the middle
                    axis y line=middle,    % put the y axis in the middle
                    axis line style={<->,color=blue}, % arrows on the axis
                    xlabel={$x$},          % default put x on x-axis
                    ylabel={$y$},          % default put y on y-axis
            }}

\begin{document}

\newcommand\aea{4}%%
\newcommand\aer{%%
  (3* \aea * sin(x) * cos(x))/((sin(x))^3+(cos(x))^3)}%%
\newcommand\aex{\aer*cos(x)}%%
\newcommand\aey{\aer*sin(x)}%%


\begin{tikzpicture}
    \begin{axis}[
            xmin=-7,xmax=7,
            ymin=-7,ymax=7,
            grid=both,
            xtick={-6,-5,...,5,6},
            ytick={-6,-5,...,5,6},
            ]
            \addplot [domain=0:90,samples=100,blue]({\aex},{\aey}); 
            \addplot [domain=136:180,samples=100,red]({\aex},{\aey}); 
            \addplot [domain=90:134,samples=100,green]({\aex},{\aey}); 
            %% the asymptote:
            \addplot [domain=-8:8,samples=10,dashed,blue]({x},{-x-\aea});
    \end{axis}
\end{tikzpicture}

\end{document}

我想改变轴线上的字体大小,以便数字不会互相重叠(是的,我希望那里的所有数字!)。

在此处输入图片描述

答案1

您可以使用来调整刻度标签的样式:

\pgfplotsset{every tick label/.append style={font=\tiny}}

在此处输入图片描述

如果您还想将刻度标签移近轴,您可以使用:

\pgfplotsset{every x tick label/.append style={font=\tiny, yshift=0.5ex}}
\pgfplotsset{every y tick label/.append style={font=\tiny, xshift=0.5ex}}

在此处输入图片描述

答案2

您还可以ticklabel style = {font=\tiny}在轴选项中使用 或\pgfplotsset

在此处输入图片描述

如果你想要不同的风格,你可以使用

        yticklabel style = {font=\tiny,xshift=0.5ex},
        xticklabel style = {font=\tiny,yshift=0.5ex}

完整代码:

% arara: pdflatex
% arara: pdflatex
% arara: open
\documentclass{standalone}
\usepackage{pgfplots}

\pgfplotsset{every axis/.append style={
                    axis x line=middle,    % put the x axis in the middle
                    axis y line=middle,    % put the y axis in the middle
                    axis line style={<->,color=blue}, % arrows on the axis
                    xlabel={$x$},          % default put x on x-axis
                    ylabel={$y$},          % default put y on y-axis
            }}

\begin{document}

\newcommand\aea{4}%%
\newcommand\aer{%%
  (3* \aea * sin(x) * cos(x))/((sin(x))^3+(cos(x))^3)}%%
\newcommand\aex{\aer*cos(x)}%%
\newcommand\aey{\aer*sin(x)}%%


\begin{tikzpicture}
    \begin{axis}[
            xmin=-7,xmax=7,
            ymin=-7,ymax=7,
            grid=both,
            xtick={-6,-5,...,5,6},
            ytick={-6,-5,...,5,6},
            yticklabel style = {font=\tiny,xshift=0.5ex},
            xticklabel style = {font=\tiny,yshift=0.5ex}
            ]
            \addplot [domain=0:90,samples=100,blue]({\aex},{\aey});
            \addplot [domain=136:180,samples=100,red]({\aex},{\aey});
            \addplot [domain=90:134,samples=100,green]({\aex},{\aey});
            %% the asymptote:
            \addplot [domain=-8:8,samples=10,dashed,blue]({x},{-x-\aea});
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容