6
$\begingroup$

This question already has an answer here:

Consider the ContourLabeled plot:

ContourPlot[Sin[x y], {x, 0, \[Pi]}, {y, 0, \[Pi]},
   Contours -> {-0.5, 0, 0.5}, ContourLabels -> All]

=>

enter image description here

Is it possible to specify the positions of the contour labels (e.g. if I wanted to center all the contour labels in the plot)?

$\endgroup$

marked as duplicate by Jens, kirma, MarcoB, ilian, Mr.Wizard Jul 21 '15 at 18:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4
$\begingroup$

Here's a hack you can use. Depending on how often you're going to need this particular functionality, I wouldn't depend on it:

Show[
 ContourPlot[Sin[x y], {x, 0, \[Pi]}, {y, 0, \[Pi]}
  , Contours -> {-0.5, 0, 0.5}
  ],
 ContourPlot[Sin[x y], {x, 0, \[Pi]}, {y, 0, \[Pi]}
  , Contours -> {-0.5, 0, 0.5}
  , ContourLabels -> All
  , RegionFunction -> Function[{x, y}, x - y > -0.05 && x - y < 0.05]
  , Background -> None
  ]
 ]

enter image description here

This depends on the fact that MMA will place the labels in the specified region, so the second version of the plot in Show is restricted to the region defined by a small strip around the line x==y.

$\endgroup$

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