I want to put a label on a contour in the ContourPlot with a text, but I can not do it. I have read all questions about this issue in the slack, but I could not find an answer to it. Let say, I want to contour plot x+y in 0 and 10 intervals of both variables, and then I choose the contour 10. Now, I want to label this contour with the text "Sommerfeld". How should I do it? this is my code:

ContourPlot[x + y, {x, 0, 10}, {y, 0, 10}, Contours -> {10}, ContourShading -> False, 
ContourStyle -> {Thickness[0.006], Dashed, Red}, 
ContourLabels -> Text["Sommerfeld"]]
  • $\begingroup$ ContourLabels takes a function or it's True/False/Automatic. So use ContourLabels -> (contourFunction[#3, {#1, #2}] &) and you should define contourFunction[c_, pos_] := Text["Sommerfeld", pos] . Note you will get the label at both ends where x+y == 10, because you added Contours->{10}. $\endgroup$
    – flinty
    Jan 6 at 18:43
  • $\begingroup$ ContourLabels -> (Rotate[ Text["Sommerfeld", {6.6, 4}, Background -> GrayLevel[0.8]], -45 Degree] &) : This is not a general solution. $\endgroup$
    – Syed
    Jan 6 at 18:49
  • $\begingroup$ Thank you. It worked. $\endgroup$
    – Mehrdad
    Jan 6 at 18:55


Your Answer

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

Browse other questions tagged or ask your own question.