21

I'm trying to draw graph similar to the one below with the Y-axis only on the RHS.

A graph with the Y-axis only on the right hand side.

The following MWE produces something close the desired result:

\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}

as this image shows:

Graph showing the Y-axis almost on the right hand side, but the line on the left has disappeared

The y-axis label has not moved to the right and the box line on the left has disappeared entirely.

Any thoughts on how to make things right and get a y-axis on the right-hand side and a box line on the left-hand side?

Thanks!

1 Answer 1

24

Replace axis y line*=right with ylabel near ticks, yticklabel pos=right (Thanks Jake):

enter image description here

Code:

\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}
2
  • Thanks, Peter. Do you know how I can get a solid line on the left-hand side of the box?
    – Richard
    Jul 18, 2012 at 21:44
  • Perfect @Jake, thanks. Feel free to edit Peter's answer or write one up of your own.
    – Richard
    Jul 18, 2012 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.