# How can I highlight one function in the Plot of a list?

I've got a Plot of a list of functions from this previous question of mine.

rp[x_, r_] := 1000 x (r + 1)/(r + x)
ratios = Table[10^n, {n, -2, 2, 4/10}]
Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True]


Now I want the sixth function, where ratio = 1, to be plotted with a PlotStyle -> AbsoluteThickness parameter. How can I do this?

-

I prefer using Style in cases like this.

rp[x_, r_] := 1000 x (r + 1)/(r + x)

ratios = Table[10^n, {n, -2, 2, 4/10}];

em = Style[#, AbsoluteThickness[4]] &;

Plot[
MapAt[em, rp[x, #] & /@ ratios, 6],
{x, 0, 1},
Evaluated -> True
]


Plot[
MapAt[em, rp[x, #] & /@ ratios, {{4}, {6}}],
{x, 0, 1},
Evaluated -> True
]


This works for styling directives except for color (by default), but colors are overridden by the default PlotStyle colors because of the output form, which is:

Style[{(* PlotStyle directive *), Line[. . .]}, (* Style directive *)]


If for whatever reason the Style method is desirable for colors as well one could use:

red = Style[#, Red, Thick] &;

Plot[
MapAt[red, x Range@5, {{2}, {4}}],
{x, 1, 10},
Evaluated -> True
] /. Style[{__, L__Line}, s__] :> Style[{L}, s]


This discards all PlotStyle directives and keeps the Style directives for lines with Style.

-
Hi Wizard. Nice, compact code. I like it, thanks. +1 for now, later maybe more :-) – stevenvh Jul 11 '12 at 16:08
+1, I did not know Plot accepted Style as a function. – rcollyer Jul 11 '12 at 16:57
@rcollyer it does, but beware that Plot's own styling overrides this so I use it only for things like Dashed and Thick, not color. – Mr.Wizard Jul 11 '12 at 17:38
Kudos - is this documented somewhere? – Yves Klett Jul 12 '12 at 6:33
@YvesKlett probably so, but after years of trying I'm still not great at finding things in the Documentation system; I have sympathy for the neophytes who post "obvious" questions. – Mr.Wizard Jul 12 '12 at 14:12

You can generate a list of additional style directives to go with your Plot, e.g. like this

rp[x_, r_] := 1000 x (r + 1)/(r + x)
ratios = Table[10^n, {n, -2, 2, 4/10}];
styles = If[# == 1, Thick, Thin] & /@ ratios;
Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True,
PlotStyle -> styles]


-
 Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True,
PlotStyle -> Map[If[#1 == 1, AbsoluteThickness[3], Automatic] &, ratios]]

-

In addition to Yves' answer, here's a way to modify the $n^\mathrm{th}$ line (corresponding to the $n^\mathrm{th}$ element of ratio) as a post-processing step:

Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True]  /.
{x___, y : {Hue[__], __} ..} :> {x, MapAt[Insert[#, Thickness[Large], 2] &, {y}, 3]}


This modifies the 3rd line (given as the third argument of MapAt). As always, structural manipulations are made on the FullForm of the expression, so if you have a more complicated or different structure, you'll have to exploit that accordingly.

Here's the above in a Manipulate to play with:

Manipulate[
Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True] /.
{x___, y : {Hue[__], __} ..} :> {x, MapAt[Insert[#, Thickness[Large], 2] &, {y}, i]},
{{i, 1}, 1, Length@ratios, 1}
]


-
´s nice! A possible (longterm) conflict may arise if the output of Plot changes in the future. Happened to me at some major version switch and resulted in a lengthyish bug hunt ;-) – Yves Klett Jul 11 '12 at 8:13
Heh yeah, that's why I put in the statutory warning that it is based on the FullForm and different structures will need to be handled differently :) – R. M. Jul 11 '12 at 8:33
The severability clause is (and was) duly noted. Just wanted to drive the point home ´cause a thing like this once came back and bit me ;-) – Yves Klett Jul 11 '12 at 8:55
@YvesKlett it only bit you once? Lucky. I've got code written for 4 major releases, and I pray every time I have to run something from an older version. Of course, some of the prayer is due to the difference in coding ability between then and now, but I digress. :) – rcollyer Jul 11 '12 at 16:56
@YvesKlett my wife actually had a computer catch fire while she was using it. – rcollyer Jul 12 '12 at 11:37

I'm on Linux and using Yves excellent answer I get the following output:

which has a very high contrast between the emphasised line and the rest.

Using a combination of thick and dashed lines seems to my eye to give more pleasing result:

rp[x_, r_] := 1000 x (r + 1)/(r + x)
ratios = Table[10^n, {n, -2, 2, 4/10}];
styles = If[# == 1, Thick, Dashed] & /@ ratios;
Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True,
PlotStyle -> styles]


-
This doesn't present a different solution, does it? – stevenvh Jul 11 '12 at 15:55
@stevenvh Thanks, I forgot to paste the modified code. – image_doctor Jul 11 '12 at 16:05