22

I wish to make a colormap where the distinction between numbers smaller than 0 and numbers greater than 0 is emphasised. So I want to make a colormap that has one sharp transition in the middle and fades to different colours on the edges. How can I do it? In the manual, I only found how to make gradual transitions.

2 Answers 2

21

You can declare your own color map, defining two colours for the transition point. Note that you might need to manually set a finer step size using the optional argument in the color map definition, to avoid incorrect colors near the transition point:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\pgfplotsset{
    colormap={blackwhite}{[5pt]
        rgb255(0pt)=(255, 200, 0);
        rgb255(500pt)=(255, 75, 0);
        rgb255(500pt)=(0, 100, 255);
        rgb255(1000pt)=(0, 255, 255)
    },
}

\begin{tikzpicture}
    \begin{axis}[colorbar]
\addplot [scatter, samples=50] {x};
\end{axis}
\end{tikzpicture}

\end{document}
1
  • 1
    Please note that the way your colormap is defined (two different color values at the same coordinate) does not work with all PDF viewers. See here for a solution: tex.stackexchange.com/questions/258873/…
    – NOhs
    Aug 6, 2015 at 11:11
5

In case you want to have only sharp transitions, you may use:

colormap={blackwhite}{[2pt] % colormap steps: 2 pt
    % white: from 0000 to 1000
    rgb(0000pt)=(1.0,1.0,1.0);
    rgb(1000pt)=(1.0,1.0,1.0);
    % gray:  from 1000 to 2000
    rgb(1000pt)=(0.5,0.5,0.5);
    rgb(2000pt)=(0.5,0.5,0.5);
    % black: from 2000 to 3000
    rgb(2000pt)=(0.0,0.0,0.0);
    rgb(3000pt)=(0.0,0.0,0.0);
},

enter image description here

You must log in to answer this question.

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