# Rescaling the colors in a colormap and the axes

I have cerated a file (workfile.dat) at the following format:

<x1> >y1> <z>
<x1> >y2> <z>
<x1> >y3> <z>

<x2> >y1> <z>
<x2> >y2> <z>
<x2> >y3> <z>

etc.


I have created a surf pgf:

using the following code:

\begin{tikzpicture}
\begin{axis}[view={0}{90},colormap/cool]
\end{axis}
\end{tikzpicture}


i would like that where the value of <z> is null that it would be white and not like in the above picture. I would like it to look like something like this:

This mean that the x-axis is represented by decimal format with two digits after the point and the y-axis is from 0 to 1 (instead of 0 to 400).

In addition i would like to know if it is possible in tikz pgf to use LogNorm for the color bar like in matplotlib.

EDIT

here is an example of what i did:

\documentclass[a4paper,10pt]{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[view={0}{90},
colormap/cool,
y filter/.code=\pgfmathparse{\pgfmathresult/400}]
\end{axis}
\end{tikzpicture}
\end{document}


and this is the output i get:

The blue lines seems to be correct, but i cant explain the gray background at the places where = 0.

EDIT 2

new example:

file data workfile.dat

1 1 0
1 2 0

2 1 0
2 2 1


output

code:

\documentclass[a4paper,10pt]{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[view={0}{90},
colormap/cool,
]
\end{axis}
\end{tikzpicture}
\end{document}


As you can see, only one element in the input data have the value "1", but nether the less, the all area is blue.

-
Hm, that's a strange result. The cool colormap doesn't contain gray. Can you make a comple minimal working example demonstrating the issue? –  Jake Mar 31 '12 at 15:17
The second picture contains a gray line color (it is not one to one). It was a line that was added above a imshow plot in matplotlib. –  Eagle Mar 31 '12 at 16:04
Just to make sure that I understand your request: you want the color map to be "modified" such that z=0 has color white, right? The second picture with the line plot has nothing to do with a surface plot at all. Perhaps what you want is a contour plot - and perhaps only with contours for z=0? –  Christian Feuersänger Mar 31 '12 at 18:30
@Christian, you are right what is important for me is that <z> = 0 it would be the color white (2nd picture) instead of gray (1st picture). –  Eagle Mar 31 '12 at 19:14
@Eagle: Which colormap did you use to create the first picture (not cool, right?)? What is the range of z values in your data? For rescaling the y range, you can use y filter/.code=\pgfmathparse{\pgfmathresult/400}, and for taking the logarithm of the z values you can use z filter/.code=\pgfmathparse{ln(\pgfmathresult)}. –  Jake Mar 31 '12 at 21:35

Per definition, a surface plot (surf) always fills the complete area by means of a "suitable" color of the colormap. Here, complete means that the background of the axis (white) is no longer visible.

In order to see "white", you have to decide if a surface plot is really what you want. If this turns out to be true (according to your question, this seems to be the case), you have primarily ONE choice: namely to define a colormap for which the value of z=0 happens to be mapped to color white.

If, however, you simply wanted to see the background color (white) and want to see a couple of lines of fixed height, you might be better off using a contour plot. I would suggest you go with a contour plot since it looks closer to your second 2d picture:

\documentclass[a4paper]{article}
\usepackage{pgfplots}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}
\begin{axis}[view={0}{90},
colormap/cool,
colorbar,
]
\addplot3[contour gnuplot] table [row sep=newline] {
1 1 0
1 2 0

2 1 0
2 2 1
};
\end{axis}
\end{tikzpicture}

\end{document}


If you really want to have a surf plot, you can still proceed as follows:

Here is an initial attempt to define a "suitable" colormap - i.e. one for which you have a surf plot for which z=0 happens to get color white:

\documentclass[a4paper]{article}
\usepackage{pgfplots}

\begin{document}
\pagestyle{empty}

\begin{tikzpicture}
\begin{axis}[view={0}{90},
colormap={custom}{color(0)=(red) color(2)=(white) color(4)=(blue)},
colorbar,
]
1 1 0
1 2 0

2 1 0
2 2 1
};
\end{axis}
\end{tikzpicture}

\begin{tikzpicture}
\begin{axis}[view={0}{90},
colormap={custom}{color(0)=(red) color(1)=(white) color(2)=(green) color(4)=(blue)},
colorbar,
]
1 1 0
1 2 0

2 1 0
2 2 1
};
\end{axis}
\end{tikzpicture}
\end{document}


In this approach, you may want to choose the correct value for shader (my choice works, another suitable one might be flat corner for your application).

I believe that the contour plot solution is what might prove to be better (less work and prettier for this application - provided the computed contours of your data are good enough).

-
thank you for your answer. At the moment i get the following error: "I do not know the key '/tikz/contour gnuplot'". I added \usepackage{gnuplot-lua-tikz} for gnuplot, but contour is still a problem. –  Eagle Apr 2 '12 at 18:31
Support for contour plots has been added in Version 1.5 . Perhaps it is unavailable without updating your installation (the most recent stable version of pgfplots is 1.5.1). –  Christian Feuersänger Apr 3 '12 at 8:27
I upgrade yesterday to v1.5.1. I saw that if i use lualatex -shell-escape foo.tex i get not what you got and if i use pdflatex -shell-escape foo.tex i get what you got. Since my data file is big, i am forced to use lualatex. Are you aware of this problem? –  Eagle Apr 3 '12 at 9:00
I looked into it and found that the binary output used by shader=interp does not work with lualatex. Until I fixed this, you will need to use another shader (like shader=flat corner). –  Christian Feuersänger Apr 3 '12 at 14:32
The incompatibility lualatex and shader=interp is fixed now; will become part of the next stable (probably 1.5.2). –  Christian Feuersänger Apr 3 '12 at 19:08