20

I want to change the color of the axis lines only without changing the color of the axis labels, tick labels etc.

MWE:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
%
\begin{document}
%
  \pgfplotsset{
    every axis/.append style={%
      red 
    }   
  }
%
  \begin{tikzpicture}
    \begin{axis}[%
        xlabel={X},
        ylabel={Y}
      ]%  
    \end{axis}
  \end{tikzpicture}
%
\end{document}

I am not aware of a pgfkey for axis lines only along the lines of /pgfplots/tick style.

1 Answer 1

26

You can set the axis labels and tick labels independently, but as Jake notes in the comments, you can also just set the axis line style. I've modified your example to show all three

\documentclass[png,border=4pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}

%
  \pgfplotsset{
    axis line style={red},
    every axis label/.append style ={blue},
    every tick label/.append style={green}  
  }
%

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[%
        xlabel={X},
        ylabel={Y}
      ]%  
    \end{axis}
  \end{tikzpicture}
%
\end{document}

output of code

3
  • +1 how about moving pgfplotsset to the preamble? :)
    – cmhughes
    Commented Dec 7, 2012 at 22:31
  • 1
    You could also use the key axis line style=red to only turn the axis lines red. That way, you don't have to look up all the styles required to turn things back to black.
    – Jake
    Commented Dec 7, 2012 at 23:12
  • @Jake Thanks. I should have left this to the experts. I'll updated my answer.
    – Alan Munn
    Commented Dec 8, 2012 at 0:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .