3
$\begingroup$

I have a ContourPlot where every contour should be displayed with a different color

ContourPlot[
 -((2500*Sqrt[13]*(x - 10000)*x^2*y)/(15625*x^4 - 13*(x - 10000)^2*y^2)),
 {x, 35, 100},
 {y, 1.4, 5.6},
 PlotLegends -> Automatic,
 Contours -> 20,
 ColorFunction -> "DarkRainbow"
]

but I get this output

enter image description here

it looks like the ColorFunction does not work. So I tried to add ColorFunctionScaling->False

which gives me this output

enter image description here

As you can see there is a difference but not what I was expecting. I tried to use ColorFunctionScaling->True as well which gives me the same output as I had in the beginning.

$\endgroup$
3
  • 1
    $\begingroup$ It appears that your function is relatively invariant to the first two arguments. Without the actual function (or at least a minimal example that also demonstrates this behavior) it is difficult to offer much help. $\endgroup$
    – Bob Hanlon
    Aug 30, 2020 at 16:15
  • $\begingroup$ Thanks for your comment. I managed to add the function to the question. $\endgroup$
    – Arji
    Aug 30, 2020 at 17:53
  • $\begingroup$ {min, max} = #[{f[x, y], 35 <= x <= 100, 1.4 <= y <= 5.6}, {x, y}] & /@ {MinValue, MaxValue} and Plot3D[f[x, y], {x, 35, 100}, {y, 1.4, 5.6}, PlotRange -> All, PlotPoints -> 100, MaxRecursion -> 5] show that your function is relatively flat except in one corner that distorts the range of the argument fed to ColorFunction $\endgroup$
    – Bob Hanlon
    Aug 30, 2020 at 18:26

1 Answer 1

6
$\begingroup$

I think the problem comes from the large values near the singularity in your function at the upper left. The default choice of contour colors seems to be using much more of the range than it shows in the plot by default.

A work around is to specify the range in the color function.

With[{min = 0, max = 20},
   ContourPlot[-((2500*Sqrt[13]*(x - 10000)*x^2*y)/(15625*x^4 - 
   13*(x - 10000)^2*y^2)), {x, 35, 100}, {y, 1.4, 5.6}, 
   PlotLegends -> Automatic, Contours -> 20, 
   PlotRange -> {min, max}, 
   ColorFunctionScaling -> False, 
   ColorFunction -> (ColorData[{"DarkRainbow", {min, max}}])
  ]
]

contour plot with specified range

$\endgroup$

Your Answer

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

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