3
$\begingroup$

Is this a bug in Contours or I am using the function incorrectly?

In the second code the function works well but in the third code it fails.

The first and third images should be the same.

ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ContourShading -> None,
  Contours -> Table[{k, Red}, {k, -4, 4, 1}]]

ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ContourShading -> None,
  Contours -> Function[{min, max}, Table[k, {k, min, max, 1}]]]

ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ContourShading -> None,
  Contours -> Function[{min, max}, Table[{k, Red}, {k, min, max, 1}]]]

enter image description here

$\endgroup$
1
  • $\begingroup$ Maybe still not implemented. ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2}, ContourShading -> None, Contours -> Function[{min, max}, Table[k, {k, min, max, 1}]], ContourStyle -> {Red, Cyan, Red}] $\endgroup$
    – cvgmt
    Commented Apr 19 at 8:22

1 Answer 1

1
$\begingroup$
$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"]

{zmin, zmax} = #[{x^2 - y^2, -2 <= x <= 2, -2 <= y <= 2}, {x, y}] & /@
  {MinValue, MaxValue}

(* {-4, 4} *)

zdelta = 1;

ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2},
 ContourShading -> None,
 Contours -> Table[
   {k, {Thick, ColorData["Rainbow"][(k - zmin)/(zmax - zmin)]}},
   {k, zmin, zmax, zdelta}],
 PlotLegends -> BarLegend[{"Rainbow", {-4, 4}},
   LegendMarkerSize -> 360],
 MaxRecursion -> 4]

enter image description here

When using Function with Contours option also use ContourStyle option

ContourPlot[x^2 - y^2, {x, -2, 2}, {y, -2, 2},
 ContourShading -> None,
 Contours -> Function[{min, max}, Table[k, {k, min, max, 1}]],
 ContourStyle ->
  ({Thick, ColorData["Rainbow"][Rescale[#, {zmin, zmax}]]} & /@
    Subdivide[zmin, zmax, 8]),
 PlotLegends -> BarLegend[{"Rainbow", {-4, 4}},
   LegendMarkerSize -> 360],
 MaxRecursion -> 4]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ This does not answer the question. I know how to color contours by other means (like without function or with restricted function and with ContourStyle). The point is to do it with function in option Contours only and to judge whether it is a bug or not. $\endgroup$ Commented Apr 19 at 12:56

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.