I would like to transfer the colors of a ListContourPlot to a ListLIC-Plot. I tried to interpolate the data of the ListContourPlot and use it as ColorFunction for the second plot but I couldn't get it to work properly, is there a better way to do this?

data1 = Table[Sin[i + j^2], {i, 0, 3, 0.1}, {j, 0, 3, 0.1}];
data2 = Table[{Sin[i + j^2], Cos[i + j^2]}, {i, 0, 3, 0.1}, {j, 0, 3, 0.1}];
f = ListInterpolation[data1];
ListContourPlot[data1, ColorFunction -> "DarkRainbow"]
ListLineIntegralConvolutionPlot[data2, ColorFunction -> Function[{x, y, vx, vy, n},
ColorData["DarkRainbow"][f[x, y]]], RasterSize -> 100]

I get the following error:

InterpolatingFunction::dmval: Input value {0.,0.} lies outside the range of
data in the interpolating function. Extrapolation will be used. >> 

The result should look remotely like the following plot

  • $\begingroup$ hat do you mean by "transfer the colors"? $\endgroup$ Commented Jun 3, 2014 at 2:01
  • $\begingroup$ I would like to color the ListLIC-Plot exacly like the ContourPlot. Basically overlaying the ListLIC-Plot with the ContourPlot plot. I add an example. $\endgroup$
    – paw
    Commented Jun 3, 2014 at 2:34

2 Answers 2

  1. You need to set ColorFunctionScaling -> False, otherwise the $x$ and $y$ passed into your ColorFunction are rescaled to lie between 0 and 1 instead of having their original values.

  2. There's a discrepancy between how ListContourPlot and ListLineIntegralConvolutionPlot interpret the dimensions of the input arrays as $x$ and $y$ coordinates. So to get the image you say you want, you have to use f[y, x] in the ColorFunction. Still, I think it's quite likely that the image you actually want is the one with f[x, y], because then the colours correspond to the $x$-component of the velocity field as one might expect from the definitions of data1 and data2.

  3. Finally, we have to rescale f to a $[0,1]$ range manually, say using Rescale, before passing it into ColorData.

 ColorFunction -> Function[{x, y, vx, vy, n}, 
   ColorData["DarkRainbow"][Rescale[f[y, x], {-1, 1}]]], 
 ColorFunctionScaling -> False, RasterSize -> 100]

enter image description here

You still get InterpolationFunction::dmval warnings, but at least you get the desired plot.

P.S. The plot I think you actually want, with f[x, y] instead of f[y, x]:

enter image description here

l1 = ListContourPlot[data1, ColorFunction -> "DarkRainbow", Frame -> False, 
                     PlotRange -> {{1.`, 31.`}, {1.`, 31.`}}, ContourStyle -> None];
l2 = ListLineIntegralConvolutionPlot[data2, ColorFunction -> GrayLevel, Frame -> False, 
                     PlotRange -> {{1.`, 31.`}, {1.`, 31.`}}];
ImageCompose[l2, {l1, .5}]

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.