0
$\begingroup$

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

Wrong ContourPlot

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 Zoomed Wrong ContourPlot

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]

Correct Plot

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!

$\endgroup$
2
  • 2
    $\begingroup$ 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. $\endgroup$
    – MassDefect
    Commented Feb 8, 2019 at 21:44
  • $\begingroup$ You are right! Thank you! $\endgroup$ Commented Feb 8, 2019 at 22:04

1 Answer 1

2
$\begingroup$

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:

enter image description here

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

$\endgroup$
2
  • $\begingroup$ 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! :) $\endgroup$ Commented Feb 8, 2019 at 22:02
  • $\begingroup$ @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. $\endgroup$
    – a20
    Commented Feb 8, 2019 at 22:40

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.