Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I label different curves in Mathematica?

Tags:

How can I label each of these lines separately :

Plot[{{5 + 2 x}, {6 + x}}, {x, 0, 10}] 

enter image description here

like image 527
500 Avatar asked Aug 28 '11 13:08

500


People also ask

What is plot label in Mathematica?

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. »

How do you add a title in Mathematica?

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.


1 Answers

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}]] 

outputa

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]}; 

four functions

like image 65
Simon Avatar answered Oct 25 '22 19:10

Simon