8
$\begingroup$

I have a problem with ContourPlot colors. In fact, i have the following table

A={x^2 + y^2 == 203.378, x^2 + y^2 == 59.1222, x^2 + y^2 == 35.2762, x^2 + y^2 == 25.4656, x^2 + y^2 == 20.1073, x^2 + y^2 == 16.7197,  x^2 + y^2 == 14.37, x^2 + y^2 == 12.6233, x^2 + y^2 == 11.2367,  x^2 + y^2 == 10.0089}

That i want to plot using the colors of "ThermometerColors". To do so, i used the following

ContourPlot[Evaluate@A, {x, -15, 15}, {y, -15, 15}, ColorFunction -> "ThermometerColors"]

However, all the plots have the same color. I think that ContourPlot associates only the first color to the functions of table A. Any idea how to associate one color from "ThermometerColors" to each function?

$\endgroup$

3 Answers 3

10
$\begingroup$

Try this:

ContourPlot[Evaluate[A], {x, -15, 15}, {y, -15, 15}, ContourStyle -> MapIndexed[{ColorData["ThermometerColors"][#2[[1]]/Length[A]]} &, A], PlotLegends -> A[[All, -1]], FrameStyle -> Black]

enter image description here

If we reverse the color order:

 ContourPlot[Evaluate[A], {x, -15, 15}, {y, -15, 15}, ContourStyle -> Reverse@MapIndexed[{ColorData["ThermometerColors"][#2[[1]]/Length[A]]} &, A], PlotLegends -> A[[All, -1]], FrameStyle -> Black]

enter image description here

$\endgroup$
7
$\begingroup$

Assuming you want contour colors to reflect contour values:

ContourPlot[Evaluate @ A[[1, 1]], {x, -15, 15}, {y, -15, 15}, 
  ContourShading -> None, 
  Contours -> Thread[{A[[All, -1]], 
    ColorData["ThermometerColors"] /@ Rescale[A[[All, -1]]]}],
  PlotLegends -> Sort @ A[[All, -1]]] 

enter image description here

Alternatively,

ContourPlot[Evaluate @ A[[1, 1]], {x, -15, 15}, {y, -15, 15}, 
  ContourShading -> None, 
  Contours -> Thread[{A[[All, -1]], 
     ColorData[{"ThermometerColors", MinMax@A[[All, -1]]}] /@ A[[All, -1]]}], 
  PlotLegends -> Sort @ A[[All, -1]]]

same picture

$\endgroup$
6
$\begingroup$
$Version

(* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *)

Clear["Global`*"]

A = {x^2 + y^2 == 203.378, x^2 + y^2 == 59.1222, x^2 + y^2 == 35.2762,
    x^2 + y^2 == 25.4656, x^2 + y^2 == 20.1073, x^2 + y^2 == 16.7197, 
   x^2 + y^2 == 14.37, x^2 + y^2 == 12.6233, x^2 + y^2 == 11.2367, 
   x^2 + y^2 == 10.0089};

ContourPlot[Evaluate@A[[1, 1]],
 {x, -15, 15}, {y, -15, 15},
 Contours -> A[[All, 2]],
 ContourShading -> None,
 ContourStyle -> (ColorData["ThermometerColors"] /@
    Subdivide[Length[A] - 1]),
 PlotLegends -> A[[All, 2]]]

enter image description here

$\endgroup$

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.