0

With Mathematica 11.3. (11.0 has some bug in ScalingFunctions).

I use Jason B.'s method, i.e. ScalingFunction ( see Logarithmic scale in a DensityPlot and its legend).

Jason B.'s code

sf = Log[#/0.00003]/Log[1/0.00003] &;
isf = InverseFunction[sf];
g1 = DensityPlot[Sinc[x]^2 Sinc[y]^2, {x, -20, 20}, {y, -20, 20}, 
PlotRange -> All, PlotPoints -> 100, ScalingFunctions -> {sf, isf}, 
ColorFunction -> "DeepSeaColors", PlotRange -> {0.00003, 1}, 
ColorFunctionScaling -> False, PlotLegends -> BarLegend[{"DeepSeaColors", 
{0.00003, 1}}, ScalingFunctions -> {sf, isf}], ImageSize -> 300]

the result is

enter image description here

Let me have a check,

d = 0.25;
g2 = Graphics[{Red, Disk[{-17, 0}, d], Red, Disk[{-17, 10}, d], Red, 
Disk[{-10, 0}, d], Red, Disk[{-4.5, 0}, d], Red, 
Disk[{-4.5, 5}, d], Red, Disk[{-4.5, 14}, d], Red, 
Disk[{0, 4.5}, d], Red, Disk[{0, 10}, d]}, Frame -> True, 
PlotRange -> {{-20, 20}, {-20, 20}}, ImageSize -> 300];
Show[g1, g2]

enter image description here

N[Sinc[x]^2 Sinc[y]^2 /. {{x -> -17, y -> 0}, {x -> -17, 
y -> 10}, {x -> -10, y -> 0}, {x -> -4.5, y -> -0}, {x -> -4.5, 
y -> 5}, {x -> -4.5, y -> 14}, {x -> 0, y -> 4.5}, {x -> 0, 
y -> 10}}]

the output is

{0.00319822, 9.46541*10^-6, 0.00295959, 0.0471884, 0.00173566, 0.000236256, 
 0.0471884, 0.00295959}

so fig1 seems correct.

Now I turn to the ListDensityPlot,

test = Flatten[Table[{x, y, Sinc[x]^2 Sinc[y]^2}, {x, -20, 20, 0.2}, {y, 
-20, 20, 0.2}], 1];
Dimensions[test]
n = Dimensions[test][[1]];
Min[test[[;; , 3]]]
Max[test[[;; , 3]]]

\[Eta] = 0.00003;
min1 = Chop[Min[test[[;; , 3]]]] + \[Eta];
max1 = Max[test[[;; , 3]]] + \[Eta];

sf = Log[(#)/min1]/Log[max1/min1] &;
(*Function[x,Log[(x)/min1]/Log[max1/min1]];*)
isf = InverseFunction[sf];
g3=ListDensityPlot[test, PlotRange -> All, ScalingFunctions -> {sf, isf},
ColorFunction -> "DeepSeaColors", PlotRange -> {min1, max1}, 
ColorFunctionScaling -> False,PlotLegends -> BarLegend[{"DeepSeaColors", 
{min1, max1}}, ScalingFunctions -> {sf, isf}]]

enter image description here

Firstly, I don't understand the ScalingFunctions->{sf,isf}, so I rescale the data myself,

dat1 = Table[{0, 0, 0}, {i, 1, n}];
For[i = 1, i <= n, i++,
{
dat1[[i, 1]] = test[[i, 1]];
dat1[[i, 2]] = test[[i, 2]];
dat1[[i, 3]] = Log[(Chop[test[[i, 3]]])/min1]/Log[max1/min1]
}]
 g4 = ListDensityPlot[dat1, PlotRange -> All, 
 ColorFunction -> "DeepSeaColors", ColorFunctionScaling -> False, 
 PlotLegends -> BarLegend[{"DeepSeaColors", {min1, max1}}, 
 ScalingFunctions -> {sf, isf}], ImageSize -> 300]

enter image description here

Finally , compare above results

GraphicsGrid[{{g1, g3, g4}}, ImageSize -> 1200]

enter image description here

The results look nice.

Finally, make ticks in scientific form

PlotLegends -> BarLegend[{"DeepSeaColors", {min1, max1}}, 
ScalingFunctions -> {sf, isf}, 
Ticks -> {Table[{10^i, DisplayForm@SuperscriptBox[10, i]}, {i, 
IntegerPart[Log10[min1]], IntegerPart[Log10[max1]], 1}], {min1, 
max1}}]

enter image description here


ScalingFunctions->{f,f^-1}, f operates on the "data", suppose the data (x,y), then (x,f(y)), and f^-1 operates on the y axis, so f^(-1)(f(y)) is invariant, more detailed ,please see ScalingFunctions - reversing a logarithmic axes

ZJX
  • 101
  • 3
  • What version of Mathematica do you have? Starting with 11.0 or so, ScalingFunctions does what you want – Lukas Lang Jun 26 '18 at 15:01
  • 1
    Hello, welcome to Mathematica.SE. I suggest the following: 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. – xzczd Jun 26 '18 at 15:29
  • @LukasLang Mathematica 11. Could you please explain what does ScalingFunctions->{f,f^-1} mean? Jason B’s method is good, but I don’t understand this f,f^-1 even I read the document. – ZJX Jun 27 '18 at 02:00
  • Something must be wrong with your test. Using your code I obtained the desired result: https://i.stack.imgur.com/VTfnZ.png I've made no modification. – xzczd Jun 27 '18 at 09:06
  • "xzczd can obtain the reasonable fig with my code, but I can't ,why? (He's mathematica 11.2, and my 11.0). " I won't be surprised if there's a bug being fixed in this period. "It seems very similar with fig.1, but not the same, some value is wrong. " No, nothing is wrong, notice your definition of sf is different from Jason B.'s. – xzczd Jun 27 '18 at 11:50
  • Thanks a lot! @xzczd, I upgrade my mathematica to 11.3 and solve this problem. – ZJX Jun 27 '18 at 15:15
  • 1
    Please move the solution to your problem to an answer. Answering your own question is perfectly fine and thanks for taking the time to post your solution! – Lukas Lang Jul 01 '18 at 12:01

0 Answers0