2

How do I change the label, axis and tick color of this plot:

\documentclass[tikz,border=5mm]{standalone}

% package for plots
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin=0,
        xmax=11100,
        ymin=0,
        ymax=5200,
        domain=0:1000,
        xlabel=Generation,
        ylabel=Fitness,
        axis line style=->,
        axis x line*=none,
        axis y line*=none,
        scaled x ticks=false,
        scaled y ticks=false,
        xtick={0,2000,...,11000},
        ytick={0,1000,...,5000},
        tick align=outside,
        every axis plot/.append style={
            line join=round,
            line cap=round,
            clip=false,    
            thick
        },
        tick align=outside,
        x tick label style={
            rotate=45,
            anchor=north east
        },
        axis on top,
        legend style={
            anchor=south,
            at={(0.5,1.1)},
            legend columns=2,
            draw=none,
            fill=none
        },
        cycle list/Dark2
        ]
        \addplot{rnd};
        \addlegendentryexpanded{Legend 1}
        \addplot{rnd};
        \addlegendentryexpanded{Legend 2}
    \end{axis}
\end{tikzpicture}
\end{document}
2
  • If I may, a minor point about your example: currently it relies on data files we don't have access to. But seeing as your question doesn't really involve the data at all, you could just replace the plots with e.g. \addplot{rnd}; Mar 17, 2021 at 19:14
  • I changed it...
    – weisbrja
    Mar 17, 2021 at 19:20

1 Answer 1

2

Regarding the axis lines (I assume that's what you meant), add the colour of your choice (and any other options) to the axis line style you already have there. I.e.

axis line style={->, green, very thick}

For the other three <foo> style={<colourname>}, where <foo> is xlabel, ylabel or tick. E.g.

    xlabel style={blue},
    ylabel style={red},
    tick style={cyan, ultra thick}

Those colours look rather ghastly of course, but I'll leave the colour choice to you. :)

enter image description here

\documentclass[tikz,border=5mm]{standalone}

% package for plots
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xmin=0,
        xmax=11100,
        ymin=0,
        ymax=5200,
        domain=0:1000,
        xlabel=Generation,
        ylabel=Fitness,
        axis line style={->, green, very thick},
        axis x line*=none,
        axis y line*=none,
        scaled x ticks=false,
        scaled y ticks=false,
        xtick={0,2000,...,11000},
        ytick={0,1000,...,5000},
        tick align=outside,
        every axis plot/.append style={
            line join=round,
            line cap=round,
            clip=false,    
            thick
        },
        tick align=outside,
        x tick label style={
            rotate=45,
            anchor=north east
        },
        axis on top,
        legend style={
            anchor=south,
            at={(0.5,1.1)},
            legend columns=2,
            draw=none,
            fill=none
        },
        cycle list/Dark2,
        xlabel style={blue},
        ylabel style={red},
        tick style={cyan, ultra thick}
        ]
 \addplot{rnd};
    \end{axis}
\end{tikzpicture}
\end{document}
4
  • For the tick labels, which I forgot, you already have an x tick label style where you can set the colour for those. Naturally there's a y tick label style as well which you can add, or use tick label style={yellow} to set all tick labels to a suitable colour. Mar 17, 2021 at 19:25
  • Thanks! That is awesome. However, how do I change the legend colors as well?
    – weisbrja
    Mar 17, 2021 at 19:42
  • @weisbrja Would it surprise you if I said "add <colour> to the legend style"? E.g. if you add blue to the legend style, all the text becomes blue. If you want to different colours, use the optional argument to \addlegendentry, e.g. \addlegendentry[red]{foo} \addlegendentry[magenta]{bar}. Mar 17, 2021 at 19:46
  • Thank you so much! It all works!
    – weisbrja
    Mar 17, 2021 at 19:55

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.