Message Boards Message Boards


PlotStyle question for efficient application.

Posted 9 years ago
1 Reply
2 Total Likes


If I have a list of functions, say 6 total, and I want to apply a plot style to the first function only, can this be done efficiently? I thought of defining the two plots separately: One for the function that requires styling, and another for the list of functions to be plotted with default styling.

What I'd like to do is something along the lines of PlotStyle -> {Thick, Automatic}, where the Automatic applies to all other functions in the list. When I tried this approach, "Thick" applied to all functions in the list except for the second one. I also realize that I could just make however many copies of "Automatic" would be required, e.g. {Thick, Automatic, Automatic, ... , Automatic}, but I'm just curious if there's a way to do this that I don't know about.

Thanks for the help!


POSTED BY: Rob Holman

No reason not to program for the PlotStyle, a bit simple one could say

In[32]:= Plot[Evaluate[Table[BesselJ[n, x], {n, 0, #}]], {x, 0, Pi E GoldenRatio}, 
   PlotStyle -> ReplacePart[Table[Automatic, {# + 1}], {2 -> Dashed, 5 -> Dotted}]] &[8]

to have the second function dashed and the fifth dotted

PlotStyle simple

or you program it

In[39]:= Clear[holman]
holman[o_, p_List, s_List] := ReplacePart[Table[Automatic, {o}], 
        Rule @@@ Transpose[{p, Take[Flatten[Table[s, {Length[p]}]], Length[p]]}]
   ] /;Length[p] <= o && Length[s] <= Length[p] && AllTrue[p, 1 <= # <= o &]

In[41]:= Plot[Evaluate[Table[BesselJ[n, x], {n, 0, #}]], {x, 0, Pi E GoldenRatio}, 
   PlotStyle -> holman[#, {2, 5, 9}, {Dashed, Dotted}]] &[10]

to alternate a list s of style options over a list p of function numbers:

positions with options

Consider to improve the function holman in a way that the style options list is filtered out to contain in the end only plottable directives.

POSTED BY: Udo Krause
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract