1
$\begingroup$

I have contour plot and I want to change the font color of the contour values. meanwhile, changing the background to white. can anybody help? this is what I've found. but it only gives 9 contours, I need arbitrary numbers as well.

ContourLabels -> (Text[
Style[#3, 
 Switch[#3, 0.1 | 0.2 | 0.3, White, 0.4 | 0.5 | 0.6, White, 
  0.7 | 0.8 | 0.9, White]], {#2, #2}, Background -> Black] &)
$\endgroup$
8
  • $\begingroup$ It is better if you start with a specific example so that the solutions we provide can be consistent. For starters, are you looking at 2D or 3D contourplot ? $\endgroup$
    – Lotus
    Dec 11, 2019 at 9:36
  • $\begingroup$ this is the example i can provide. $\endgroup$
    – user68857
    Dec 11, 2019 at 9:40
  • $\begingroup$ ContourPlot[Sqrt[x y], {x, 0, 3}, {y, 0, 3}, ColorFunction -> "IslandColors", FrameLabel -> {Style[ "\!(*SubscriptBox[(T), (i)])(keV)", FontSize -> 14, FontFamily -> "Times"], Style["\!(*SubscriptBox[(T), (e)])(keV)", FontSize -> 14, FontFamily -> "Times"]}, $\endgroup$
    – user68857
    Dec 11, 2019 at 9:41
  • $\begingroup$ ContourLabels -> (Text[ Style[#3, Switch[#3, 0.1 | 0.2 | 0.3, White, 0.4 | 0.5 | 0.6, White, 0.7 | 0.8 | 0.9, White]], {#2, #2}, Background -> Black] &), ContourLabels -> (Text[#3, {#2, #2}, Background -> Black] &), LabelStyle -> {Directive[Black, Bold], (FontSize -> 16), FontFamily -> "Times"}, PlotLegends -> Placed[BarLegend[Automatic, LegendLabel -> Style["[Rho]R(g.\!(*SuperscriptBox[(cm), (-2)]))", FontSize -> 12]], {After, Center}]] $\endgroup$
    – user68857
    Dec 11, 2019 at 9:41
  • $\begingroup$ I have never seen a Switch inside Style before. What is the intention of this ? Is this a documented example ? $\endgroup$
    – Lotus
    Dec 11, 2019 at 9:49

1 Answer 1

1
$\begingroup$

How about this example then?

ContourPlot[Sin[x y], {x, 0, 3}, {y, 0, 3}, 
 ColorFunction -> "IslandColors", 
 ContourLabels -> (Text[Style[Framed[#3], 20, White], {#1, #2}, 
     Background -> Black] &)]

The Background is Black, Labels are in White, and the Label Font Size is set to 20.

$\endgroup$
1
  • $\begingroup$ Thank you very much. i exactly wanted this. the code i had made it too difficult. thank you very much indeed. $\endgroup$
    – user68857
    Dec 11, 2019 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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