# Color the labels given by Label in Plot consistently with the colour of the corresponding function

Consider the following toy example:

With[{
data = Table[
Labeled[Sin[n x], n],
{n, 1, 5}
]
},
Plot[
data,
{x, 0, Pi},
PlotRange -> All
]
]


which produces the following plot: In cases like this, it may be hard to figure out what label corresponds to what plot. Is there an easy way to have the labels coloured consistently with the colour of the corresponding line? This would mean in this example to have the 1 coloured blue, the 2 coloured orange, etc.

• In such a case a usual Legend is much better. – corey979 May 29 '17 at 17:27
• @corey979 I agree for this toy example, but sometimes you have data which is well described with Labeled, except for some of the lines that overlap on the right – glS May 29 '17 at 17:31

## 1 Answer

You can set the color of the label using Style and assign the color of the curves to be the same as the color of the labels. Further you can control the font face, boldness and size, etc...

First define a list of colors

colors = {Black, Orange, Red, Purple , Blue} Use colors and Style to assign the color of the text (text arbitrarily set to Bold and font size 14 as an example).

With[
{
data = Table[Labeled[Sin[n x],
Style[n, Bold, 14, colors[[n]]]], {n, 1, 5}]
},
Plot[data, {x, 0, Pi}, PlotRange -> All, PlotStyle -> colors]
] ## Update

In order to use the default colors (described here) replace colors with ColorData[97, "ColorList"]

With[
{
data = Table[Labeled[Sin[n x],

Style[n, Bold, 14, ColorData[97, "ColorList"][[n]]]],
{n, 1, 5}]
},
Plot[data, {x, 0, Pi}, PlotRange -> All,
PlotStyle -> ColorData[97, "ColorList"]]
] • this is the straightforward solution, yes. I was however hoping for a solution that wouldn't force me to specify my own color scheme for the plot, instead using the default one used by Mathematica for the plot – glS May 29 '17 at 16:14
• @glS Update that answers your new question. – Jack LaVigne May 29 '17 at 16:48