PgfPlot 的 Y 轴仅在右侧

PgfPlot 的 Y 轴仅在右侧

我正在尝试绘制类似于下面的图形,其中 Y 轴仅在 RHS 上。

仅在右侧有 Y 轴的图表。

以下 MWE 产生接近所需结果:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[scale=0.75]
    \begin{axis}[ylabel=Y-Axis, xlabel=X-Axis
, xmin=2, xmax=10, ymin=0, ymax=12, clip=false, axis y line*=right]
    \foreach \blah in {0.9,0.5,0.2,0.1,0.05,0.02,0.01,0.005}{
        \addplot[mark=none, domain=2:10, thick] {-ln(\blah/x^2)/ln(x)} node [pos=0,left] {$c_2=$}; %Varying c_2 values
    }
    \end{axis}
\end{tikzpicture}

\end{document}

如图所示:

图表显示 Y 轴几乎位于右侧,但左侧的线已消失

y 轴标签没有向右移动,并且左侧的框线已完全消失。

关于如何使事情正确并在右侧得到 y 轴而在左侧得到框线,您有什么想法吗?

谢谢!

答案1

替换axis y line*=rightylabel near ticks, yticklabel pos=right(感谢杰克):

在此处输入图片描述

代码:

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}[scale=0.75]
    \begin{axis}[
        ylabel=Y-Axis, xlabel=X-Axis, 
        xmin=2, xmax=10, ymin=0, ymax=12, clip=false, 
        %axis y line*=right% replaced this option with:
        ylabel near ticks, yticklabel pos=right
        ]
    \foreach \blah in {0.9,0.5,0.2,0.1,0.05,0.02,0.01,0.005}{
        \addplot[mark=none, domain=2:10, thick] {-ln(\blah/x^2)/ln(x)} node [pos=0,left] {$c_2=$}; %Varying c_2 values
    }
    \end{axis}
\end{tikzpicture}

\end{document}

相关内容