Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I know how to change the color for all axis in pgfplots:

\begin{axis}[blue]
\end{axis}

This makes all four edges of the plot blue. Another example is there: PGFPlots: Change the color of axis lines

Question: How do I only change the color on one of the axis, for example the left y-axis?

share|improve this question
2  
Half an answer: separate axis lines,y axis line style={blue}. Changes only the y-axis lines, but both of them. –  Torbjørn T. Feb 5 '13 at 16:21

1 Answer 1

up vote 5 down vote accepted

There's no option to draw the individual lines using different styles at the moment. It's not too hard to add, though. If you copy the following code chunk into your preamble, you can set the axis line styles individually, so you could say

\begin{axis}[
    separate axis lines,
    first x axis line style=red,
    second x axis line style={ultra thick, dashed},
    first y axis line style=blue
  ]
  \addplot {rnd};
\end{axis}

to get


Here's the code chunk:

\pgfplotsset{
    every first x axis line/.style={},
    every first y axis line/.style={},
    every first z axis line/.style={},
    every second x axis line/.style={},
    every second y axis line/.style={},
    every second z axis line/.style={},
    first x axis line style/.style={/pgfplots/every first x axis line/.append style={#1}},
    first y axis line style/.style={/pgfplots/every first y axis line/.append style={#1}},
    first z axis line style/.style={/pgfplots/every first z axis line/.append style={#1}},
    second x axis line style/.style={/pgfplots/every second x axis line/.append style={#1}},
    second y axis line style/.style={/pgfplots/every second y axis line/.append style={#1}},
    second z axis line style/.style={/pgfplots/every second z axis line/.append style={#1}}
}

\makeatletter
\def\pgfplots@drawaxis@outerlines@separate@onorientedsurf#1#2{%
    \if2\csname pgfplots@#1axislinesnum\endcsname
        % centered axis lines handled elsewhere.
    \else
    \scope[/pgfplots/every outer #1 axis line,
        #1discont,decoration={pre length=\csname #1disstart\endcsname, post length=\csname #1disend\endcsname}]
        \pgfplots@ifaxisline@B@onorientedsurf@should@be@drawn{0}{%
            \draw [/pgfplots/every first #1 axis line] decorate {
                \pgfextra
                % exchange roles of A <-> B axes:
                \pgfplotspointonorientedsurfaceabsetupfor{#2}{#1}{\pgfplotspointonorientedsurfaceN}%
                \pgfplots@drawgridlines@onorientedsurf@fromto{\csname pgfplots@#2min\endcsname}%
                \endpgfextra 
                };
        }{}%
        \pgfplots@ifaxisline@B@onorientedsurf@should@be@drawn{1}{%
            \draw [/pgfplots/every second #1 axis line] decorate {
                \pgfextra
                % exchange roles of A <-> B axes:
                \pgfplotspointonorientedsurfaceabsetupfor{#2}{#1}{\pgfplotspointonorientedsurfaceN}%
                \pgfplots@drawgridlines@onorientedsurf@fromto{\csname pgfplots@#2max\endcsname}%
                \endpgfextra 
                };
        }{}%
    \endscope
    \fi
}%
\makeatother
share|improve this answer
    
Thank you very much. :) –  Foo Bar Feb 5 '13 at 17:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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