4
$\begingroup$

I have a Contourplot of F[r,x], which I just wanted to keep some specific contours, however, I wish to label the contours not with their actual numerical values but with some other numbers. So instead of the numerical labels shown below, I wish to label my contour correspondingly with {0.01,0.1,1,3}. What should I do?

ContourPlot[F[r,x],{r,0.5,5},{x,10,40},
Contours->{2Log[0.01],-2Log[0.1],0,-2.19},
ContourLabels->True]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Do not paste LaTex for code. Paste the code and format with {} button. $\endgroup$ – Edmund Apr 18 '17 at 20:00
4
$\begingroup$

Generally, ContourLabels is a function. So you have to use a function to link labels with their values. It's easy to specify 2 separate lists of labels and corresponding values and the use Association to link them. I use characters for labels for clarity of example, but numbers also can be used, --- as strings or directly. Note this approach has a sound logic in a sense that keys of Association should be unique, and so are the contour values, which are used as keys.

zvalues={.1,.2,.3,.4};
labels={"a","b","c","d"};
link=AssociationThread[zvalues->labels];
f=Text[Style[link[#3],15,Red],{#1,#2}]&;

ContourPlot[x/Exp[x^2+y^2],{x,0,2},{y,-2,2},
    Contours->zvalues,
    ContourLabels->f,
    PlotLegends->Automatic]

enter image description here

$\endgroup$

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.