2

to recreate a plot within TIKZ, I'm using the viridis colormap with sampled colors option, which works almost perfectly. My problem is that I get the correct number of steps, but the first and last color always differ from the one of the continuous map. Therefore, the highest value is green and not the desired yellow.

Is there a way to set the first and last color used in the sampled colormap? Or is the interpolation function known, which calculated the sampled color values from viridis?

Best regards,

ps

Edit: Some code to illustrate my problem below

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
  \begin{axis}[colormap name=viridis,
               colorbar]  
  \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
  \begin{axis}[colormap name=viridis,
               colorbar,
               colorbar sampled, colorbar style={samples=4}, colormap access=piecewise const]  
  \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
  \begin{axis}[colormap name=viridis,
               colorbar,
               colorbar sampled, colorbar style={samples=8}, colormap access=piecewise const]  
  \end{axis}
\end{tikzpicture}
\begin{tikzpicture}
  \begin{axis}[colormap name=viridis,
               colorbar,
               colorbar sampled, colorbar style={samples=12}, colormap access=piecewise const]  
  \end{axis}
\end{tikzpicture}
\end{document}
  • Welcome to TeX.SE. It would be helpful if you composed a fully compilable minimal working example (MWE) including \documentclass and the appropriate packages that sets up the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – user36296 Jan 30 at 9:41
  • Would \begin{axis}[ colormap={example}{ samples of colormap=(4 of viridis) }, colorbar, colorbar sampled, colorbar style={samples=4}, colormap access=piecewise const] \end{axis} be a workaround? – user36296 Jan 30 at 10:20
2

Workaround:

\documentclass[tikz]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
 colormap={example}{ samples of colormap=(4 of viridis) }, 
 colorbar, 
 colorbar sampled, 
 colorbar style={samples=4}, 
 colormap access=piecewise const
] 
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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.