I have a custom colormap. And I have a plot with a colorbar.
Without custom colormap: No border around the colorbar, as intended. Looks perfectly fine in Mac Preview.
With custom colormap: Black border around the colorbar in TeX-studio preview. No colorbar, only black frame, in Mac Preview.
Here a MWE. Just uncomment the custom colorbar and hopefully you will get the same strange result as I do and know how to fix it:
\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz,pgfplots}
%\pgfplotsset{colormap={blueColormap}{[2pt]%
% color(0000pt)=(RoyalBlue!50!black);
% color(1000pt)=(RoyalBlue!50!black);
% color(1000pt)=(RoyalBlue!70!black);
% color(2000pt)=(RoyalBlue!70!black);
% color(2000pt)=(RoyalBlue!90!black);
% color(3000pt)=(RoyalBlue!90!black);
% color(3000pt)=(RoyalBlue!90!white);
% color(4000pt)=(RoyalBlue!90!white);
% color(4000pt)=(RoyalBlue!70!white);
% color(5000pt)=(RoyalBlue!70!white);
% color(5000pt)=(RoyalBlue!50!white);
% color(6000pt)=(RoyalBlue!50!white);
% }
%}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colorbar,
colorbar style={
ytick style={draw=none},
ytick={0,1,2,3,4,5,6},
yticklabels={0,1,2,3,4,5,6},
axis line style = { draw = none }
},
point meta min=0,
point meta max=6
]
\foreach \n in {0,1,...,5}
%{\edef\temp{\noexpand
\addplot[ultra thick, smooth,mesh,point meta={\n+0.5},domain={0:1}] {x^\n}; %}\temp}
\end{axis}
\end{tikzpicture}
\end{document}
Best Answer
The root cause is that your
colormap
definition is invalid andpgfplots
failed to complain: the colormap contains multiple values for the same offset.The problem can be reduced to the following minimal example:
This example shows fine in
evince
andxpdf
, but Acrobat Reader shows a popup that the pdf is invalid.The solution is to eliminate double offsets. The following works fine:
or, in order to keep your "jumps":
Note that this last file takes a very long time since the colormap contains thousands of data points -- and since the involved colors are given in CMYK which requires extra effort (compare the warning stated by pgfplots).
My suggestions to overcome performance limitations are * reduce the sampling density of the colormap (i.e. do not use
2pt
as mesh width on a scale of [0:6000], increase the mesh width considerably) * redefine the input color as RGB color which simplifies the rendering of the color barEDIT
You also asked "why is there an unanticipated black frame, but only for my custom colormap?"
This is due to the fact that
blueColormap
is a CMYK colormap (becauseRoyalBlue
is defined in CMYK). Pgfplots can handle CMYK shadings, but PGF cannot. In order to satisty this constraint, Pgfplots applies special steps for thecolorbar
which, unfortunately, causedraw=none
to be ignored. I have just found and fixed this issue; it was present whenever an\addplot3
statement occurred in an axis.A simple workaround is to add
colormap default colorspace=rgb
before you define your custom colormap: