First time posting on SE, trying my best with formatting, behaviour and such.
I'm trying to create a stand-alone colorbar, to use next to a image. I want to have 10 discrete colors, that I define in my custom colormap. Why does not TikZ use these 10-rgb colors in the colorbar? It seems to interpolate in between and apply some shading.
But it ends up looking like this:
I have used MS Paint to find the RGB-colors of the colorbar. Why are they now showing as the RGB-colors I entered? My code is below.
\pgfplotsset{
% define the custom colormap
colormap={my colormap}{
rgb255=(0,0,255),
rgb255=(0, 100, 255),
rgb255=(0, 160, 255),
rgb255=(0, 210, 255),
rgb255=(0, 255, 255),
rgb255=(0, 255, 0),
rgb255=(0, 255, 255),
rgb255=(0, 255, 200),
rgb255=(0, 255, 200),
rgb255=(255, 0 ,0),
},
}
\begin{tikzpicture}
\begin{axis}[
hide axis,
scale only axis,
height=0pt,
width=0pt,
colormap name=my colormap,
colorbar sampled,
colorbar horizontal,
point meta min=0,
point meta max=1,
colorbar style={
xlabel={Relative density},
samples=11,
height=0.5cm,
width=10cm,
xtick style={
color=black}
},
]
\addplot [draw=none] coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
Thanks, Johan
Best Answer
The RGB Values that you add are wrong. And you have to add
colormap access=piecewise const
otherwise the colour displayed is dependent on the colours defined before and after it.Just to demonstrate it lets look at
Where the first block should be black and the second white.