3

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

user37694
  • 423
  • 4
  • 10

1 Answers1

12

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

lowriniak
  • 2,412
  • 10
  • 15
  • My Mathematica version is 10. With this code I do not have any output. – user37694 Nov 30 '16 at 12:19
  • 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. – lowriniak Nov 30 '16 at 13:45
  • Callout is a new function in Mathematica 11.0 – matmma Nov 30 '16 at 12:50
  • I've got 10.4 and it don't work using Placed. But it does work using Labeled. Thank you. Tony Dee – Antony DeGance May 25 '17 at 21:07