Transfer ColorFunction from ListContourPlot to ListLIC-Plot - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-23T18:46:07Z https://mathematica.stackexchange.com/feeds/question/48984 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/48984 0 Transfer ColorFunction from ListContourPlot to ListLIC-Plot paw https://mathematica.stackexchange.com/users/4539 2014-06-03T01:24:15Z 2014-06-03T03:37:05Z <p>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?</p> <pre><code>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 -&gt; "DarkRainbow"] ListLineIntegralConvolutionPlot[data2, ColorFunction -&gt; Function[{x, y, vx, vy, n}, ColorData["DarkRainbow"][f[x, y]]], RasterSize -&gt; 100] </code></pre> <p>I get the following error:</p> <pre><code>InterpolatingFunction::dmval: Input value {0.,0.} lies outside the range of data in the interpolating function. Extrapolation will be used. &gt;&gt; ... </code></pre> <p>The result should look remotely like the following <img src="https://i.imgur.com/Y3cO1Zc.jpg" alt="plot"></p> https://mathematica.stackexchange.com/questions/48984/-/48987#48987 2 Answer by Dr. belisarius for Transfer ColorFunction from ListContourPlot to ListLIC-Plot Dr. belisarius https://mathematica.stackexchange.com/users/193 2014-06-03T03:15:50Z 2014-06-03T03:15:50Z <pre><code>l1 = ListContourPlot[data1, ColorFunction -&gt; "DarkRainbow", Frame -&gt; False, PlotRange -&gt; {{1.`, 31.`}, {1.`, 31.`}}, ContourStyle -&gt; None]; l2 = ListLineIntegralConvolutionPlot[data2, ColorFunction -&gt; GrayLevel, Frame -&gt; False, PlotRange -&gt; {{1.`, 31.`}, {1.`, 31.`}}]; ImageCompose[l2, {l1, .5}] </code></pre> <p><img src="https://i.stack.imgur.com/CFVI0.png" alt="Mathematica graphics"></p> https://mathematica.stackexchange.com/questions/48984/-/48988#48988 2 Answer by Rahul for Transfer ColorFunction from ListContourPlot to ListLIC-Plot Rahul https://mathematica.stackexchange.com/users/484 2014-06-03T03:30:20Z 2014-06-03T03:37:05Z <ol> <li><p>You need to set <code>ColorFunctionScaling -&gt; False</code>, otherwise the \$x\$ and \$y\$ passed into your <code>ColorFunction</code> are rescaled to lie between 0 and 1 instead of having their original values.</p></li> <li><p>There's a discrepancy between how <code>ListContourPlot</code> and <code>ListLineIntegralConvolutionPlot</code> 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 <code>f[y, x]</code> in the <code>ColorFunction</code>. Still, I think it's quite likely that the image you <em>actually</em> want is the one with <code>f[x, y]</code>, because then the colours correspond to the \$x\$-component of the velocity field as one might expect from the definitions of <code>data1</code> and <code>data2</code>.</p></li> <li><p>Finally, we have to rescale <code>f</code> to a \$[0,1]\$ range manually, say using <code>Rescale</code>, before passing it into <code>ColorData</code>.</p></li> </ol> <pre><code>ListLineIntegralConvolutionPlot[data2, ColorFunction -&gt; Function[{x, y, vx, vy, n}, ColorData["DarkRainbow"][Rescale[f[y, x], {-1, 1}]]], ColorFunctionScaling -&gt; False, RasterSize -&gt; 100] </code></pre> <p><img src="https://i.stack.imgur.com/KHu25.png" alt="enter image description here"></p> <p>You still get <em>InterpolationFunction::dmval</em> warnings, but at least you get the desired plot.</p> <p>P.S. The plot I think you actually want, with <code>f[x, y]</code> instead of <code>f[y, x]</code>:</p> <p><img src="https://i.stack.imgur.com/LdQ20.png" alt="enter image description here"></p>