# ContourPlot fails in a simple equation

I'm very new with Mathematica, and I'm struggling with a very simple problem.

I want to plot this

ContourPlot[Sqrt[-1 + (4 k^2)/(1 + k^2 Z)^2], {k, 0.4, 2500}, {Z,
0.001, 1.0}, ClippingStyle -> Automatic,
ScalingFunctions -> {"Log", "Log", "Log"},
PlotLegends ->
BarLegend[Automatic, All,
LabelingFunction -> (Style[NumberForm[#, 3]] &)], PlotPoints -> 20,
MaxRecursion -> 4, ColorFunction -> "Rainbow",
ContourLabels -> False, Contours -> 20,
FrameLabel -> {"|\!$$\*OverscriptBox[\(k$$, $$~$$]\)|", "Z"},
PlotRange -> {{0.4, 2500}, {.001, 1.2}, {.2, 40}},
ImageSize -> Medium]


Doing that I obtain this

But I know that the function is always <1 when Z>0.5 which is in contrast with the plot.

Zooming (PlotRange -> {{0.4, 5}, {.5, 1.0}, {.2, 40}) I obtain

again wrong, since the function is always less than 1 in this domain.

Decreasing the domain of Z, i obtain something more correct (but i need the full range!)

ContourPlot[Sqrt[-1 + (4 k^2)/(1 + k^2 Z)^2], {k, 0.4, 2500}, {Z, 0.5, 1.0}, ClippingStyle -> Automatic, ScalingFunctions -> {"Log", "Log", "Log"}, PlotLegends -> BarLegend[Automatic, All, LabelingFunction -> (Style[NumberForm[#, 3]] &)], PlotPoints -> 20,MaxRecursion -> 4, ColorFunction -> "Rainbow", ContourLabels -> False, Contours -> 20, FrameLabel -> {"|\!$$\*OverscriptBox[\(k$$, $$~$$]\)|", "Z"}, PlotRange -> {{0.4, 5}, {.5, 1.0}, {.2, 40}}, ImageSize -> Medium]


I tried increasing/decreasing the PlotPoints, MaxRecursion, WorkinPrecision and others but I really can't get the clue of the problem!

Can someone solve my problem?

Thank you!

• I think there might be a problem with the way you're constructing your legend. If I use PlotLegends -> Automatic I get a much different legend. – MassDefect Feb 8 '19 at 21:44
• You are right! Thank you! – Giulio Benetti Feb 8 '19 at 22:04

You mistake lies in the LabelingFunction.

You wrote:

BarLegend[Automatic, All,
LabelingFunction -> (Style[NumberForm[#, 3]] &)]


but, at the same time your plot range is:

PlotRange -> {{0.4, 2500}, {.001, 1.2}, {.2, 40}}


so you are taking a range from 0.2 to 40 and put it in your Style[NumberForm[#,3]] (this is what the # means). Just remove the LabelingFunction, put it to automatic, or change the plotrange to the maximum of the area you're plotting, and you get this:

In General, it is good to stick with the Automatic options and then add other options as you need them.

• You are right. Thank you bjorn for your contribution. Now I only have to find a way to reduce the decimal digits of the legend. Anyway you helped me a lot, thank you again and I wish you the best! :) – Giulio Benetti Feb 8 '19 at 22:02
• @GiulioBenetti ah, I see, you wnat to keep a certain format of the numbers. Your issue lies with the fact that you are plotting the colors logarithmically, but not using a logarithmic scaling in your legend. I have seen several questions related to this before (that is, your issue lies in the legend scaling, not the ContourPlot). Perhaps you could edit the title and your question to make this more clear. – a20 Feb 8 '19 at 22:40