17

I have a plot with a mesh and it uses a lovely colormap, however, I can't find a way to make tikzpicture only use colorblind friendly colors. I'm not colorblind, but I know at least some of the people who will be reading my technical document are. Any ideas on how to fix it?

Minimal Working Example

For example, the following code produces a figure with a colormap that may not be acceptable:

\documentclass[varwidth=true, border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[nodes near coords={(\coordindex)},
            title=Rectangle from matrix input]
            % note that surf implies 'patch type=rectangle'
            \addplot3[surf,shader=interp,samples=2,
            patch type=rectangle] 
            {x*y};
        \end{axis}
    \end{tikzpicture}
\end{document}

This results in:

enter image description here

  • 2
    A related question asking about how to use colors defined by ColorBrewer in PGFPlots. According to their website, "ColorBrewer is an online tool designed to help people select good color schemes for maps and other graphics." – I Like to Code Feb 28 '14 at 1:03
  • 5
    Colour blindness exists in a multitude of flavours. Could you maybe specify which one you are referring to? Or do you want it to be useable by people with any type of colourblindness? – Saaru Lindestøkke Feb 28 '14 at 1:12
  • As Bart Arondson already stated: There are basically two types of colour blindness: red-green and blue-yellow colour blindness, the first affects about 5% of population, the second is very rare, so may statements concern the first kind: You should not use red and green colours combined in your colour map. I am not colourblind, but sometimes work with colourblind pupils. – user31729 Feb 28 '14 at 5:06
  • 1
    @BartArondson ChristianH With sufficient contrast of colors it doesn't matter which one an individual has. You can avoid it safely and it doesn't need to be like black and yellow colors all around like a radiation sign to be colorblind friendly unlike many others might think. I have red-green btw. – percusse Feb 28 '14 at 7:02
  • 1
    @percusse: ILikeToCode linked to question with an answer of Jake. You could give an answer here which of the colour styles are good distinguishable from your point of view. (Sic! But truly no pun intended.) Jake wrote this as PGFPlots library, would be interesting, whether this could be more generalized for TikZ. – Speravir Feb 28 '14 at 19:28
4

I think the following will work for any type of colorblindness as it uses only one color:

\documentclass[varwidth=true, border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}
    \pgfplotsset{
        colormap={whitered}{
            color(0cm)=(white);
            color(1cm)=(orange!75!red)
        }
    }
    \begin{tikzpicture}
        \begin{axis}[
            colormap name=whitered,
            title=Rectangle from matrix input,
            colorbar,
            colorbar style={
                at={(-0.3,0)},
                anchor=south west,
                height=0.6*\pgfkeysvalueof{/pgfplots/parent axis height},
                title={$f(x,y)$}
            }]
            \addplot3[surf,samples=30] {x*y};
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

| improve this answer | |
  • But this will not work for all use cases, I think. – Speravir Mar 6 '14 at 18:59
  • Why do you think that? – Martin Thoma Mar 6 '14 at 20:15
  • The information content may be too high to show it with one colour shading. Already for the case already linked in comments below the question you would be lost, cf. Pre-defined color cycles à la RColorBrewer?. (I know, that it would probably be anyway better to split the information into several diagrams there.) There are reasons, why for instance cartographs use more than one shaded colour. I have your answer nonetheless upvoted. – Speravir Mar 6 '14 at 21:26

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.