# PGFplots-warning: Sorry, the colorbar is uninitialised - your axis has no color data

When trying to place a colorbar for a plot with only graphics, I get this warning:

Sorry, the colorbar is uninitialized - your axis has no color data. Consider using 'point meta=f(x)' or something like that. I am using a color range of [0,1] for the colorbar.

So, how can I properly initialize the colorbar?

\documentclass[border=5mm]{standalone}

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

\begin{document}
\begin{tikzpicture}
\begin{axis}[
colorbar, colorbar style ={
point meta min =100,
point meta max =200
},
]
\addplot graphics [xmin=0,xmax=50,ymin=0,ymax=10] {example-image};
\end{axis}
%
\end{tikzpicture}
\end{document}

• I do not know any clean way to switch off the warning but of course you can cheat, i.e. make pgfplots happy by adding \addplot [domain=0:50,point meta=100+2*x,draw=none] {0.1*x}; where draw=none ensures that your figure does not get spoiled. – marmot Aug 26 '18 at 23:35
• @marmot Not clean but works :) I am a bit lazy to look for the meaning of point meta=100+2*x but I found that point meta = 0 is enough for completing the task. – Diaa Aug 26 '18 at 23:44
• Yes, it is just a warning anyway. The reason for this formula is to make sure meta runs from 100 to 200, but as you say it's unnecessary. – marmot Aug 26 '18 at 23:47

## 1 Answer

This is either because the point meta values are checked before the colorbar style keys or because the axis itself does not get access to the colorbar style keys. Thus, making the warning disappear you could either state the point meta keys directly to the axis options or state them in the \addplot options.

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
colorbar,
% either state the point meta keys in the axis' options ...
point meta min=100,
point meta max=200,
]
\addplot [
%            % ... or in the \addplot' options to make the warning disappear
%            point meta min=100,
%            point meta max=200,
] graphics [xmin=0,xmax=50,ymin=0,ymax=10] {example-image};
\end{axis}
\end{tikzpicture}
\end{document}