I want to use ListDensityPlot and ScalingFunctions -> {"Log", None}] to show "data" results. The demension of data is 34*200.

In[1]:= data // Dimensions

Out[1]= {34, 200}

If i use

 ListDensityPlot[data, PlotRange -> All, 
  ScalingFunctions -> {"Log", None}]]

to generate the figure, everything is ok. As shown below,

the result without Datarange

But when I try to set the Datarange of "X" from 0.1 to 20, "Y" is from 1 to 34, the final result will be "different", as shown below.

ListDensityPlot[data, PlotRange -> All, 
 ScalingFunctions -> {"Log", None}, DataRange -> {{0.1, 20}, {1, 34}}]

the result with Datarange

Why does it lead to such results? Is this a bug? How can I configure it to achieve what I want?


1 Answer 1


"13.1.0 for Linux x86 (64-bit) (June 16, 2022)"

This issue has been noted as a bug in several previous posts:

Search results - scalingfunctions datarange

enter image description here

An example that replicates the issue in OP:

data = Table[Max[x, y], {x, 1, 10, .1}, {y, 0, 10, .1}];

ldp1 = ListDensityPlot[data, ScalingFunctions -> {"Log", None}, 
   ImageSize -> 400];
ldp2 = ListDensityPlot[data, ScalingFunctions -> {"Log", None}, 
   ImageSize -> 400, DataRange -> {{0, 5}, {1, 100}}];
Row[{ldp1, ldp2}, Spacer[10]]

enter image description here

A work-around: post-process the output generated without the option DataRange and modify tick labels in accordance with desired data range values:

modifyTickLabels[oldRange_, newRange_] := ReplaceAll[ _FormBox -> ""]@
    ReplaceAll[FormBox[s_String?(StringMatchQ[NumberString]), ___] :> 
       Rescale[FromDigits[s], oldRange, newRange]]@
     AbsoluteOptions[#, FrameTicks][[1]] &;

Use modifyTickLabels to construct a custom DisplayFunction:

displayFunction = Show[#, modifyTickLabels[{0, 100}, {0, 5}]@ #] &;

Use the option DisplayFunction -> displayFunction instead of DataRange ->... in ListDensityPlot:

ListDensityPlot[data, ScalingFunctions -> {"Log", None}, 
 ImageSize -> 500, DisplayFunction -> displayFunction]

enter image description here

If we replace "Log" with "Reverse" above, the first code block gives:

enter image description here

and, after correction, we get

enter image description here

  • $\begingroup$ Thank you very much for your help. I thought the new version of MMA could achieve this function through other settings, instead of constructing custom tick labels. $\endgroup$
    – Tim
    May 10, 2023 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.