2

I'm observing some odd behavior on my colormaps. Here is a minimum working code example:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
    colormap={parula}{[1pt] rgb255(0pt)=(53,42,135); rgb255(1pt)=(15,92,221); rgb255(2pt)=(18,125,216); rgb255(3pt)=(7,156,207); rgb255(4pt)=(21,177,180); rgb255(5pt)=(89,189,140); rgb255(6pt)=(165,190,107); rgb255(7pt)=(225,185,82); rgb255(8pt)=(252,206,46); rgb255(9pt)=(249,251,14)}, % BROKEN
    %colormap={parula}{ rgb255=(53,42,135); rgb255=(15,92,221); rgb255=(18,125,216); rgb255=(7,156,207); rgb255=(21,177,180); rgb255=(89,189,140); rgb255=(165,190,107); rgb255=(225,185,82); rgb255=(252,206,46); rgb255=(249,251,14)}, % FIXED
    }
\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
            colormap access=piecewise const,
            colorbar horizontal,
            colorbar sampled,
            colorbar style={samples=11},
            point meta min=0,
            point meta max=1,
        ]
        \end{axis}
    \end{tikzpicture}
\end{document}

This results in the following colorbar: Bad Result The problem is that the 5th color repeats twice (repeat in the 6th position) and the 10th color doesn't show at all.

Now, it turns out I actually have a fix, which is to replace the 4th line of code with the line commented out on the 5th line. The main difference is that the pt specification for each color is not included. Here is the corrected result: Good Result

So, my question is why I am getting the bad behavior with the code that included the pt specification for each color? You may wonder why I care if I already have a fix. The reason is that I'm using Matlab2Tikz, which outputs the colormap with the pt specification included, which they appear to be quite deliberate about. So I have a few options: (1) Fix my colormaps after getting output from matlab2tikz with the fix shown above, (2) Change matlab2tikz script to do it right, (3) Better option?

Before I take action, I'm just trying to understand the root cause for the issue i'm seeing. User error? Bug with Matlab2Tikz? Bug with PGFPLOTS? Etc?

1

seems to be short of a final value, the following gives desired result (above)

 \documentclass[border=5pt]{standalone}
 \usepackage{pgfplots}
        \pgfplotsset{
        colormap={parula}{[1pt] rgb255(0pt)=(53,42,135); rgb255(1pt)=(15,92,221); rgb255(2pt)=(18,125,216); rgb255(3pt)=(7,156,207); rgb255(4pt)=(21,177,180); rgb255(5pt)=(89,189,140); rgb255(6pt)=(165,190,107); rgb255(7pt)=(225,185,82); rgb255(8pt)=(252,206,46); rgb255(9pt)=(249,251,14); rgb255(10pt)=(255,255,0)}, % NOT BROKEN
        %colormap={parula}{ rgb255=(53,42,135); rgb255=(15,92,221); rgb255=(18,125,216); rgb255=(7,156,207); rgb255=(21,177,180); rgb255=(89,189,140); rgb255=(165,190,107); rgb255=(225,185,82); rgb255=(252,206,46); rgb255=(249,251,14)}, % FIXED
        }
    \begin{document}
        \begin{tikzpicture}
            \begin{axis}[
                colormap access=piecewise const,
                colorbar horizontal,
                colorbar sampled,
                colorbar style={samples=11},
                point meta min=0,
                point meta max=1,
            ]
            \end{axis}
        \end{tikzpicture}
    \end{document}
  • Thanks, this does give an alternative fix for me. Still, my issue is now I need to manually either fix every plot I make or make a custom change to Matlab2tikz. I'm still looking for some insight as to where the "issue" is. Should I report a bug for matlab2tikz or to PGFPLOTS. Or is this just an obscure use case and everything is performing as expected? – Matt Oct 23 '18 at 20:15
  • Not sure, without delving down to underlying code, if it works well enough by adding one group of identical ? characters to each line I would look at that as the way to go for now. It may be you need to consider a compat=setting in either package since one package may need to be adapted on the fly to match another package version related behaviour. I am having other issues with one bit of pgfplots which may be down to other packages it calls or even the way the tex engine calls it at the time, but can't yet see any related difference in the way it behaves so suspect its a version sync issue. – user170109 Oct 24 '18 at 0:39
  • Actually in my case it was nothing wrong with pgfplots but the external package – user170109 Oct 24 '18 at 22:27

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.