1
$\begingroup$

The documentation says it's the:

$f$ contour levels

but I'm not sure what it means. My data is of the form:

data = {{x1, y1, f1}, {x2, y2, f2}, ...}

I'd expect that the argument supplied would be the value of $f$ at the point, or the triple $(x,y,f)$. But after some try and error, I think it's neither.

$\endgroup$
  • $\begingroup$ Isn't it effectively your $f_i$? $\endgroup$ – BlacKow Sep 30 '16 at 20:25
  • $\begingroup$ @BlacKow Nope. I did a test with integers $f$, and I'm getting non-integer values at ColorFunction. $\endgroup$ – becko Sep 30 '16 at 20:33
  • 1
    $\begingroup$ Because it interpolates your $f(x,y)$ and the it chooses at what value of $z$ (which is $f$) to draw a contour line. If it chooses non-integer, it tries to call your ColorFunction for non-integer. $\endgroup$ – BlacKow Sep 30 '16 at 20:35
  • 1
    $\begingroup$ I presume you're aware of ColorFunctionScaling? $\endgroup$ – J. M. will be back soon Oct 2 '16 at 4:21
  • 1
    $\begingroup$ You can specify what $z$ -values you want to use for contours: Contours -> {0,1,2,3,...} $\endgroup$ – BlacKow Oct 4 '16 at 4:03
3
$\begingroup$
data = Flatten[#, 1] &@
   Table[{x, y, 10 Exp[-x^2 - y^2]}, {x, -2, 2, 0.1}, {y, -2, 2, 0.1}];

Our color function will give red for even numbers, blue for odd and black for non-integers.

colFun[z_] := If[z == Round[z], #, Black] &@If[EvenQ@Round@z, Red, Blue];

Then the following code gives black only for outside, it means that the ColorFunction is sampled at integers only.

ListContourPlot[data, ColorFunction -> colFun, 
 Contours -> Range[0.5, 10, 1], ColorFunctionScaling -> False]

enter image description here

If you remove the Contours option you will get just black square. Also you can check it with @george2079's code:

Reap[ListContourPlot[data, Contours -> Range[0.5, 10, 1], 
   ColorFunctionScaling -> False, ColorFunction :> (Sow[{##}] &)]][[2,1]]
(* {{0.00335463}, {1.}, {2.}, {3.}, {4.}, {5.}, {6.}, {7.}, {8.}, {9.},{10.}} *)
$\endgroup$
1
$\begingroup$

this is useful to see what you are getting..

data = Flatten[Table[ {i, j, 100 Sin[i j] }, {i, 0, 5}, {j, 0, 5}], 1];
Reap[ListContourPlot[ data, ColorFunction :> (Sow[{##}] &)]][[2, 1]]

{{0.}, {0.132899}, {0.235553}, {0.338208}, {0.440862}, {0.543517}, {0.646171}, {0.748826}, {0.85148}, {1.}}

Reap[ListContourPlot[ data, ColorFunctionScaling -> False, 
   ColorFunction :> (Sow[{##}] &)]][[2, 1]]

{{-95.8924}, {-70.}, {-50.}, {-30.}, {-10.}, {10.}, {30.}, {50.}, {70.}, {98.9358}}

note I did Sow[{##}] just in case we were being fed a sequence, but in this case its just the one value.

You can see in the unscaled case the values given to the color function are the binned values of the data, and in the default case the values are scaled to the range 0-1, which makes sense so your color function can be something like Hue

$\endgroup$
  • $\begingroup$ Note that I set ColorFunctionScaling -> False, and still the values fed to ColorFunction are not the function values $f_i$. $\endgroup$ – becko Oct 3 '16 at 13:12
  • $\begingroup$ right, they are not function values. The data range is divided up into nice even increments and each increment range gets a color, hence a call to ColorFunction. Note the ColorFunction is only called about 10 times regardless of the number of data points. $\endgroup$ – george2079 Oct 3 '16 at 13:16

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.