# DensityPlot of function with infinite value

I want to density plot this function:

 concentration2D[x_, y_] :=
rate/(2*Pi*diff)*E^((-(y - 0)*advection)/(2*100))*
BesselK[0,
Norm[{x, y} - {0,0}]/(Sqrt[(100*500)/(
1 + (500)/(4*100))])];


(I have variables in there and I've replaced them with their values to make the answer easier, that's why the calculations are not done)

The problem is that at the point {0,0} this takes an infinite value, which blows the DensityPlot's colorscale out of proportion and I don't get a nice range of colors on my plot. How can I tell Mathematica not to consider that value in its colorscaling?

Thanks to J.M.'s comments, I have this:

 DensityPlot[
concentration2D[x, y], {x, -interval, interval}, {y, -interval,
interval}, PlotLegends -> Automatic,
ColorFunction -> (ColorData[{"TemperatureMap", {0, 1}}][#1] &)]


I do get a much nicer range of colors, but there is a big part of the plot that is left white near the discontinuity, as if the color scale doesn't assign any colors to it at all, and playing with the range of the colordata doesn't address it. Any ideas?

• Hmm, $K_n(z)$ is indeed singular at $0$, and decays otherwise. What range of values would you like to be colored? – J. M.'s torpor Jul 10 '16 at 19:40
• @J.M. I'd like x and y to range between -250 and 250. The odd thing is that mathematica does try to scale it somehow. The values near $(0,0)$ are around 8 or 9 before blowing directly to infinity. – Mike Jul 10 '16 at 19:43
• I was talking about $z$-values, actually. :) $x$ and $y$ can of course be easily controlled in the limits for DensityPlot[]. Since $K_0$ is always positive, maybe a coloring scheme that colors all values in $(0,10)$ should suffice, or do you need coloring in a wider range? – J. M.'s torpor Jul 10 '16 at 19:45
• @J.M. Ah... yes everything is positive here, so something between $(0,10)$ would be just fine. Could you demonstrate how to force a range on the color's of density plot? – Mike Jul 10 '16 at 19:48
• You could apply the solution I gave in your previous question; that is, look into controlling the range of values of ColorData[], and remember to set ColorFunctionScaling -> False when you do. FYI: "M10DefaultDensityGradient" is the default gradient in version 10, if the default is what you want to adjust. – J. M.'s torpor Jul 10 '16 at 19:53

## 1 Answer

You can density plot a transformation of the function and subsequently inverse transform the bar labels using the Ticks options:

concentration2D[x_, y_] = 1/x^2 + y;
trans[x_] = E^x/(1 + E^x);
inverse[y_] = Log[y/(1 - y)];

With[{ticks = 18},
DensityPlot[trans[concentration2D[x, y]], {x, -1, 1}, {y, -1, 1},
ColorFunction -> "Rainbow", PlotLegends -> Automatic] /. BarLegend[{a_, b_}, c___] :>
BarLegend[{a, b}, Ticks -> N[{#, Quiet[inverse[#]]} & /@ (Range @@ Append[#,
-Subtract @@ #/(ticks - 1)] &[SetPrecision[b, \[Infinity]]]), 3], c]] For the particular function I plotted the transformation turned out to be way too flat at the region with high values.

• Your trans[] is built-in as LogisticSigmoid[], BTW. – J. M.'s torpor Jul 10 '16 at 20:25