18

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

Martin Thoma
  • 18,799
  • 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 01: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 01: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. –  Feb 28 '14 at 05:06
  • @BartArondson: It doesn't matter which colorblindness, there are schemes posted online safe for all types of colorblind, for example: http://jfly.iam.u-tokyo.ac.jp/color/ – sciencenewbie Feb 28 '14 at 06:20
  • 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 07: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
  • @Speravir I'm using already a variant of it for my own taste. Colors themselves are not the point. It depends on what sits on which color unfortunately. So there is some context dependency. For example the new MWE has no problems for me but put it on a yellowish or green background and I'm in lala land. – percusse Mar 06 '14 at 08:44

1 Answers1

5

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

Martin Thoma
  • 18,799