# Wrong ticks in colorbar using pgfplots

I'm using pgfplots and addplot3 to show a 3D function, provided by the following csv:

100,2.0,100
500,2.0,500
1000,2.0,1000
1500,2.0,1500
2000,2.0,2000

100,2.1,158.489
500,2.1,930.823
1000,2.1,1995.26
1500,2.1,3116.74
2000,2.1,4276.94

100,2.2,250.901
500,2.2,1732.86
1000,2.2,3981.07
1500,2.2,6476.04
2000,2.2,9146.1

100,2.3,398.107
500,2.3,3225.97
1000,2.3,7942.87
1500,2.3,13456.1
2000,2.3,19557.4

100,2.4,630.843
500,2.4,6004.51
1000,2.4,15848.9
1500,2.4,27955.1
2000,2.4,41825.6

100,2.5,1000
500,2.5,11173.7
1000,2.5,4.75107
1500,2.5,2.81728
2000,2.5,2.26659

100,2.6,1583.01
500,2.6,2.49369
1000,2.6,1.65541
1500,2.6,1.45015
2000,2.6,1.35367

100,2.7,93.0216
500,2.7,1.47484
1000,2.7,1.24744
1500,2.7,1.17567
2000,2.7,1.13921

100,2.8,2.64684
500,2.8,1.20907
1000,2.8,1.11044
1500,2.8,1.07747
2000,2.8,1.06059

100,2.9,1.64157
500,2.9,1.10231
1000,2.9,1.05243
1500,2.9,1.03585
2000,2.9,1.02746

100,3.0,1.32898
500,3.0,1.05254
1000,3.0,1.02562
1500,3.0,1.01693
2000,3.0,1.01265


I'm using this code:

\pgfplotsset{
ytick={2.0,2.2,...,3},
xtick=data,
ztick={1e0,1e1,1e2,1e3,1e4},
}

\begin{figure}[ht]
\centering
\begin{tikzpicture}
\begin{axis}[view/h=135,colorbar right,ymin=1.9,ymax=3.1,zmode=log,xlabel style={sloped},ylabel style={sloped},ymajorgrids=true,x dir=reverse,
colorbar style={yticklabel=$10^{\pgfmathparse{\tick}\pgfmathprintnumber\pgfmathresult}$}]
\end{axis}
\end{tikzpicture}
\end{figure}


which results in the following plot:

As you can see, the labels on the ticks in the colorbar are wrong, as the range should be more or less [10^0,10^4], as it is correctly shown in the plot on the left.

Any idea on how can I fix this?

This happens because PGFPlots uses the natural log for transforming your data. You can tell it to use base 10 by setting log base z=10:

\documentclass{article}

\usepackage{pgfplots}

0.5,
0.5,
0.5,0.5
1.5,1.5
1.5,1.5
2.5,
2.5,2.5
3.5,3.5
}\datatable

\begin{document}
\pgfplotsset{
ytick={2.0,2.2,...,3},
xtick=data,
ztick={1e0,1e1,1e2,1e3,1e4},
}

\begin{figure}[ht]
\centering
\begin{tikzpicture}
\begin{axis}[view/h=135,colorbar right,ymin=1.9,ymax=3.1,zmode=log,log base z=10, xlabel style={sloped},ylabel style={sloped},ymajorgrids=true,x dir=reverse,
colorbar style={yticklabel=$10^{\pgfmathparse{\tick}\pgfmathprintnumber\pgfmathresult}$}]
100,2.0,100
500,2.0,500
1000,2.0,1000
1500,2.0,1500
2000,2.0,2000

100,2.1,158.489
500,2.1,930.823
1000,2.1,1995.26
1500,2.1,3116.74
2000,2.1,4276.94

100,2.2,250.901
500,2.2,1732.86
1000,2.2,3981.07
1500,2.2,6476.04
2000,2.2,9146.1

100,2.3,398.107
500,2.3,3225.97
1000,2.3,7942.87
1500,2.3,13456.1
2000,2.3,19557.4

100,2.4,630.843
500,2.4,6004.51
1000,2.4,15848.9
1500,2.4,27955.1
2000,2.4,41825.6

100,2.5,1000
500,2.5,11173.7
1000,2.5,4.75107
1500,2.5,2.81728
2000,2.5,2.26659

100,2.6,1583.01
500,2.6,2.49369
1000,2.6,1.65541
1500,2.6,1.45015
2000,2.6,1.35367

100,2.7,93.0216
500,2.7,1.47484
1000,2.7,1.24744
1500,2.7,1.17567
2000,2.7,1.13921

100,2.8,2.64684
500,2.8,1.20907
1000,2.8,1.11044
1500,2.8,1.07747
2000,2.8,1.06059

100,2.9,1.64157
500,2.9,1.10231
1000,2.9,1.05243
1500,2.9,1.03585
2000,2.9,1.02746

100,3.0,1.32898
500,3.0,1.05254
1000,3.0,1.02562
1500,3.0,1.01693
2000,3.0,1.01265
};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

• Btw, I see that the color gradients in the plot are different in your figure, how is that? – Filippo Bistaffa Jun 7 '14 at 12:11