右侧为 Y 刻度标签,左侧为 y 轴标签

右侧为 Y 刻度标签,左侧为 y 轴标签

有没有办法只将 y 轴刻度标签向右移动?该选项yticklabel pos=right也会自动移动轴标签。

这里是有关轴标签如何移动的 MWE:

\documentclass[xcolor=x11names]{article}
\usepackage{graphicx}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{palatino}
\usepackage[euler-digits]{eulervm}
\begin{document}
    \begin{tikzpicture}
        \newcommand{\scaling}{0.5}
        \pgfplotsset{
            myaxis/.style={
                width={\scaling\textwidth},
                height={\scaling\textwidth/1.61803398875},
            },
        }
        \begin{semilogyaxis}[
            myaxis,
            xlabel={$x$},
            ylabel={$y$},
            ymin=1e-6,
            ymax=1e12,
            xmin=-4,
            xmax=4,
            scale only axis,
            ytick={1e-5,1e2,1e9},
            yticklabels={$10^{-5}$,$10^2$,$10^{9}$},
            yticklabel pos=right
        ]
        \addplot[very thick,color=blue!70!green!80,samples=500,domain=-4:4] {abs(1/(1+x))};
        \addplot[very thick,color=blue!30!green!80,samples=500,domain=-4:4] {abs(1/(1+x*x))};
        \end{semilogyaxis}
    \end{tikzpicture}
\end{document}

答案1

可以手动调整标签定位。

\documentclass[xcolor=x11names]{article}
\usepackage{graphicx}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{palatino}
\usepackage[euler-digits]{eulervm}
\begin{document}
    \centering
    \begin{tikzpicture} %
        \newcommand{\scaling}{0.5}
        \pgfplotsset{ %
            myaxis/.style={ %
                width={\scaling\textwidth}, %
                height={\scaling\textwidth/1.61803398875}, %
            }, 
        } %
        %  
        \pgfplotsset{every axis y label/.append style={yshift=7.75cm}}  %adjust the position with yshift           
        \begin{semilogyaxis}[ %
            myaxis, %
            xlabel={$x$}, %
            ylabel={$y$}, %
            ymin=1e-6, %
            ymax=1e12, %
            xmin=-4, %
            xmax=4, %
            scale only axis,
            ytick={1e-5,1e2,1e9},
            yticklabels={$10^{-5}$,$10^2$,$10^{9}$},
            yticklabel pos=right
        ] %
        \addplot[very thick,color=blue!70!green!80,samples=500,domain=-4:4] {abs(1/(1+x))};
        \addplot[very thick,color=blue!30!green!80,samples=500,domain=-4:4] {abs(1/(1+x*x))};
        \end{semilogyaxis} %
    \end{tikzpicture} %
\end{document}

在此处输入图片描述

答案2

另一种方法是通过禁用轴标签ylabel={}然后在左侧添加 y 标签节点来禁用轴标签。clip=false但是,这是必需的。

在此处输入图片描述

代码

\documentclass[xcolor=x11names]{article}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% General Setup

\usepackage{graphicx}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.9}

\usepackage{palatino}
\usepackage[euler-digits]{eulervm}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Begin Document

\begin{document}

    \centering
    \begin{tikzpicture} %
        \newcommand{\scaling}{0.5}
        \pgfplotsset{ %
            myaxis/.style={ %
                width={\scaling\textwidth}, %
                height={\scaling\textwidth/1.61803398875}, %
            }, 
        } %
        %               
        \begin{semilogyaxis}[ %
            myaxis, %
            xlabel={$x$}, %
            ylabel={$y$}, %
            ymin=1e-6, %
            ymax=1e12, %
            xmin=-4, %
            xmax=4, %
            scale only axis,
            ytick={1e-5,1e2,1e9},
            yticklabels={$10^{-5}$,$10^2$,$10^{9}$},
            yticklabel pos=right,ylabel={},
            clip=false,
        ] %
        \addplot[very thick,color=blue!70!green!80,samples=500,domain=-4:4] {abs(1/(1+x))};
        \addplot[very thick,color=blue!30!green!80,samples=500,domain=-4:4] {abs(1/(1+x*x))};
         \node[rotate=90] () at (axis cs: -5,1000) {$y$};
        \end{semilogyaxis} %
    \end{tikzpicture} %
\end{document}

相关内容