I'd like to create an image with tikz that uses just a part of a predefined colormap or shading. More precisley, if I have e.g. the jet-colormap
I like to create several rectangles that use the jet colormap, but not the full range but rather some part:

I tried different approaches with a colormap, e.g. directly via colorbars (example 1) and with shadings (exmaple 2). But i didn't came up with a solution.
example 1
\documentclass[]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\pgfplotsset{ticks=none}
\begin{axis}[
hide axis,
scale only axis,
height=0pt,
width=0pt,
colormap/jet,
colorbar horizontal,
colorbar style={
width=10cm,
}]
\addplot [draw=none] coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
\end{document}
example 2
\documentclass[]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\definecolor{C1}{RGB}{19,128,67}
\definecolor{C2}{RGB}{255,255,255}
\definecolor{C3}{RGB}{154,0,79}
\pgfdeclareverticalshading{someShading}{50bp}{
color(0bp)=(C1);
color(25bp)=(C2);
color(50bp)=(C3)
}
\shade [shading=someShading](1,4) +(-.5,-3.5) rectangle ++(.5,3.5);
\end{tikzpicture}
\end{document}
I'd like to avoid creating data for the individual rectangles to control the range of the colormap. The 'best case' would be to be able to adress an actual interval, e.g. choose a value between [0,1] or to adress an percentage interval like [0%,100%].
Thanks a lot for any help,
M



\expandafterallows to insert the result of some previous calculation in a place without touching any of the other macro's expectations. In my case, it inserts\resultinto the argument of\pgfdeclarehorizontalshading{tempshading}{1cm}{<here>}. It is a defensive -- and sometimes unavoidable -- expansion technique. See https://tex.stackexchange.com/questions/12668/where-do-i-start-latex-programming/27589#27589 and the "TeX programming notes" linked therein for details. Sometimes there are alternatives to this expansion, sometimes not. – Christian Feuersänger Apr 10 '18 at 18:05