Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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]  

enter image description here

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

share|improve this question

5 Answers 5

up vote 8 down vote accepted

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
]

Mathematica graphics

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

Mathematica graphics


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]

Mathematica graphics

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

share|improve this answer
1  
Hi Wizard. Nice, compact code. I like it, thanks. +1 for now, later maybe more :-) –  stevenvh Jul 11 '12 at 16:08
2  
+1, I did not know Plot accepted Style as a function. –  rcollyer Jul 11 '12 at 16:57
3  
@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
1  
@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

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

Mathematica graphics

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]

Mathematica graphics

share|improve this answer
1  
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

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

enter image description here

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

enter image description here

share|improve this answer
    
´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 :) –  rm -rf 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
1  
@YvesKlett my wife actually had a computer catch fire while she was using it. –  rcollyer Jul 12 '12 at 11:37
 Plot[Map[rp[x, #] &, ratios], {x, 0, 1}, Evaluated -> True, 
 PlotStyle -> Map[If[#1 == 1, AbsoluteThickness[3], Automatic] &, ratios]]
share|improve this answer

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]

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.