How can I label each of these lines separately :
Plot[{{5 + 2 x}, {6 + x}}, {x, 0, 10}]
PlotLabel->label specifies a label to give. Any expression can be used as a label. It will be given by default in TraditionalForm. Arbitrary strings of text can be given as "text". » PlotLabel->StandardForm[expr] will give a label in standard Wolfram Language form. »
You can create title and section headings in a Wolfram System notebook by choosing the appropriate cell style in the Format ▶ Style menu. Add a Title cell to your notebook by choosing Format ▶ Style ▶ Title: Note that the cursor that appears in the Title cell is very large.
There's some nice code that allows you to do this dynamically in an answer to How to annotate multiple datasets in ListPlots.
There's also a LabelPlot
command defined in the Technical Note Labeling Curves in Plots
Of course, if you don't have too many images to make, then it's not hard to manually add the labels in using Epilog
, for example
fns[x_] := {5 + 2 x, 6 + x}; len := Length[fns[x]]; Plot[Evaluate[fns[x]], {x, 0, 10}, Epilog -> Table[Inset[ Framed[DisplayForm[fns[x][[i]]], RoundingRadius -> 5], {5, fns[5][[i]]}, Background -> White], {i, len}]]
In fact, you can do something similar with Locators
that allows you to move the labels wherever you want:
DynamicModule[{pos = Table[{1, fns[1][[i]]}, {i, len}]}, LocatorPane[Dynamic[pos], Plot[Evaluate[fns[x]], {x, 0, 10}], Appearance -> Table[Framed[Text@TraditionalForm[fns[x][[i]]], RoundingRadius -> 5, Background -> White], {i, len}]]]
In the above I made the locators take the form of the labels, although it is also possible to keep an Epilog
like that above and have invisible locators that control the positions. The locators could also be constrained (using the 2nd argument of Dynamic
) to the appropriate curves... but that's not really necessary.
As an example of the above code with the functions with the labels moved by hand:
fns[x_] := {Log[x], Exp[x], Sin[x], Cos[x]};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With