# How can I easily visualize density plots with singularities with the least loss of detail?

I'm trying to visualize electric fields. StreamPlot is helpful:

ef[q_, source_, at_] = (k q)/Norm[source - at]^3 (at - source)
myfield[x_, y_] =
(ef[-1, {-1, 0}, {x, y}] + ef[+1, {+1, 0}, {x, y}]) /. k -> 8.99 10^9;
StreamPlot[myfield[x, y], {x, -3, 3}, {y, -3, 3}] But when I want to see the strength of the field as well, StreamDensityPlot understandably chokes because $\lim_{(x,y) \to (\pm 1,0)} \lVert \texttt{myfield}[x,y] \rVert = \infty$. This is what I get:

StreamDensityPlot[myfield[x, y], {x, -3, 3}, {y, -3, 3},
ColorFunction -> "TemperatureMap"] Now, I can adjust the scalar field by Mining the actual Norm with some fixed value:

StreamDensityPlot[{myfield[x, y],
Min[Norm[myfield[x, y]], 10^11]}, {x, -3, 3}, {y, -3, 3},
ColorFunction -> "TemperatureMap"] But this requires some trial and error to find a good value, and it still doesn't look particularly great (there's noticeable clipping). More importantly, there's really only two regions: the poles (red) and the farfield (blue); I don't really gain much insight into the field strength, at, say, $(0, \frac{1}{2})$.

Throwing a Log in there gives you more contrast, but you still have to fiddle with the clamp:

StreamDensityPlot[{myfield[x, y],
Min[Log[Norm[myfield[x, y]]], 28]}, {x, -3, 3}, {y, -3, 3},
ColorFunction -> "TemperatureMap"] Hence my question. How can I get StreamDensityPlot to

• yield nice output even when the domain contains singularities,
• such that I can clearly see both the singularities and the farfield, and the regions in between,
• while still retaining a reasonable degree of physical accuracy,
• and as automatically as possible? (e.g., I don't very much like having to manually specify the scalar field)

I read the main StreamDensityPlot documentation and skimmed the "Options" section (that's how I found that you can manually specify the scalar field) but didn't see anything pertinent.

• Also, any comments about my Mathematica code/style would be appreciated—I have much to learn! – wchargin Apr 15 '15 at 4:36
• – user9660 Apr 15 '15 at 6:10
• Welcome to Mathematica.SE! I suggest the following: 0) Browse the common pitfalls question 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Dr. belisarius Sep 11 '15 at 17:28

vals = Table[Norm[myfield[x, y]], {x, -3, 3, 6/100}, {y, -3, 3, 6/100}];
m = Mean@Log@Flatten@vals;
st = StandardDeviation@Log@Flatten@vals;

(* For some cases you may use these instead
m = NIntegrate[Log@Norm[myfield[x, y]], {x, -3, 3}, {y, -3, 3}]/36;
st = NIntegrate[(m - Log@Norm[myfield[x, y]])^2, {x, -3, 3}, {y, -3, 3}]/36 // Sqrt;
*)
Manipulate[
sta = a st;
StreamDensityPlot[{
myfield[x, y],
Rescale[Log@Norm[myfield[x, y]], {m - sta, m + sta}]},
{x, -3, 3}, {y, -3, 3}, ColorFunction -> "TemperatureMap",
ColorFunctionScaling -> False],
{a, 1, 5}] • Ooh, clever to use the standard deviation! I'll look into this. – wchargin Aug 13 '15 at 4:13