I would like to plot a DensityPlot of two 1/r^2 functions on a 2D plane (this is supposed to visualize the inverse squared force field law between two points). If I plot the code below I get only two big 'blobs' instead of two points (or at least two smaller blobs) with a smooth decreasing intensity shading, because Mathematica cuts the top of the z values which obviously go to infinity. How can I extend the plotting range in the third z-coordinate two make these blobs appear smaller. I tried with PlotRange and PlotRegion but nothing works. Using PlotRange --> All does not work because in this case it is a function which diverges (not just a sin/cos^n function as asked elsewhere). Then the opposite problem occurs, just two tiny points appear (see second image), no in between solution could I find. It needs a much more finer color gradient. Can this be done? Thanks in advance.

x1 = -1; y1 = 0; x2 = 1; y2 = 0; Dist = 2.5*x2; 
f = ColorData["LakeColors"];
 1/((x1 - x)^2 + (y1 - y)^2) + 1/((x2 - x)^2 + (y2 - y)^2), {x, -Dist,
   Dist}, {y, -Dist, Dist}, ColorFunction -> ColorData["SolarColors"]]

enter image description here enter image description here

  • $\begingroup$ Add PlotRange -> All. Thus: With[{Dist = 2.5}, DensityPlot[Sum[1/SquaredEuclideanDistance[{x, y}, pt], {pt, {{-1, 0}, {1, 0}}}], {x, -Dist, Dist}, {y, -Dist, Dist}, ColorFunction -> "SolarColors", PlotRange -> All]] $\endgroup$ – J. M.'s technical difficulties Apr 13 '18 at 6:16
  • $\begingroup$ I did, but since it is a 'spiked' function, the divergence points just appear as two tiny points and nothing else. It does not work as with a sin/cos^n function. It would be nice to have something in between, i.e. a larger color gradient which goes from infinity to zero with more shades (logarithmically? or something of the sort?) Is this possible? $\endgroup$ – Mark Apr 13 '18 at 6:38
  • 1
    $\begingroup$ What you can try is to manually perform a logarithmic (or some other) rescaling of the color function: ColorFunction -> (ColorData["SolarColors", Log10[#]] &), ColorFunctionScaling -> False. $\endgroup$ – J. M.'s technical difficulties Apr 13 '18 at 6:47
  • $\begingroup$ Ah... ok, that could be an option. Will see if that can be optimzed. Thanks so far. $\endgroup$ – Mark Apr 13 '18 at 6:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.