3
$\begingroup$

I wrote the following code:

Plot[{Sin[x], Cos[x]}, {x, 0, 10}, PlotStyle -> {Red, {Blue, Thick}}, PlotLegends -> "Expressions"]

I want to have label for every function in plot. Please see the following picture: enter image description here

$\endgroup$
  • 1
    $\begingroup$ Plot[{Sin[x], Cos[x]}, {x, 0, 10}, PlotStyle -> {Red, {Blue, Thick}}, PlotLabels -> Placed["Expressions", Below]] $\endgroup$ – corey979 Nov 30 '16 at 12:22
  • $\begingroup$ @corey979 This code not work in Mathematica version10. $\endgroup$ – user37694 Nov 30 '16 at 12:30
  • $\begingroup$ @user37694 This works fine in 10.4 $\endgroup$ – Feyre Nov 30 '16 at 12:50
  • $\begingroup$ See How can I mark each of several plots with a parameter that identifies it?. $\endgroup$ – corey979 Nov 30 '16 at 12:52
  • 1
    $\begingroup$ Then go basic. Plot[{Sin[x], Cos[x]}, {x, 0, 10}, PlotStyle -> {Red, {Blue, Thick}}, Epilog -> {Text["sin(x)", {3/2 Pi, -1.1}], Text["cos(x)", {Pi, -1.1}]}, PlotRange -> {-1.2, 1.2}] $\endgroup$ – Feyre Nov 30 '16 at 12:59
10
$\begingroup$

Edit to add Labeled details

You can use Callout for 'in-plot' labels, for example:

Plot[{
  Callout[Sin[x], "Sin[x]", Below], 
  Callout[Cos[x], "Cos[x]", Below]
}, 
{x, 0, 10}, 
PlotStyle -> {Red, {Blue, Thick}}
]

Callout

Alternatively if you do not have version 11 you can use Labeled to get a similar effect, like this:

Plot[{
  Labeled[Sin[x], "Sin[x]", Below], 
  Labeled[Cos[x], "Cos[x]", Below]
}, 
{x, 0, 10}, 
PlotStyle -> {Red, {Blue, Thick}}
]

Labeled

This does lose the lines but you could make a labeling function to customise this, for example:

plotLabel[text_] := Graphics[{
  Line[{{0, -1}, {0, 0}}], 
  Text[Style[text, 10], {0, -2}]
},
ImageSize -> 30
]

Which with Labeled makes:

CustomLabel

$\endgroup$
  • $\begingroup$ My Mathematica version is 10. With this code I do not have any output. $\endgroup$ – user37694 Nov 30 '16 at 12:19
  • $\begingroup$ Callout is a new function in Mathematica 11.0 $\endgroup$ – matmma Nov 30 '16 at 12:50
  • $\begingroup$ Callout is a new function in version 11. In version 10 you can use Labeled in its place to get a similar output, but it won't give you the lines from the text to the plot line. You could construct your own label creation function with Graphics if you had a specific style in mind. $\endgroup$ – lowriniak Nov 30 '16 at 13:45
  • $\begingroup$ I've got 10.4 and it don't work using Placed. But it does work using Labeled. Thank you. Tony Dee $\endgroup$ – Antony DeGance May 25 '17 at 21:07

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.