# Non-cyclical PlotStyle?

I'm trying to plot a Table of functions. Since the number of elements is unspecified, I want to specify a "repeating" graphic directive.

Supposing I have two direcives, m and s, I would like to do something like:

PlotStyle -> {m, s...}


But I can only specify

PlotStyle -> {m, s}


However, since this specification is cyclical, I get (what would be like)

{m, s, m, s, m, s...}


So I'm forced to specify

PlotStyle -> {m, s, s, s, s, s, s, s, s, s, s, s}


for the exact number of elements in the Table, and breaking the graphical presentation for another number of elements.

Is there a way I can specify a directive for a number n of first elements in the Table, and another for the remaining elements?

• One way to at least make the solution you have more manageable (ie, less code) would be something like PlotStyle -> Flatten[{m, Table[s, 10]} where 10 is the number of elements. – Carl Lange Jan 13 '19 at 21:12

My usual approach would be to programmatically generate the set of styles:

fns = x^Range[5];

Plot[fns, {x, -1, 1}, PlotStyle -> Prepend[Table[Black, 4], Red]]


You could also use Style to override the setting coming from PlotStyle:

Plot[Evaluate[MapAt[Style[#, Red] &, fns, 1]], {x, -1, 1},
PlotStyle -> Black]


• Or Show[ Plot[First@fns, {x, -1, 1}, PlotStyle -> Red], Plot[Rest@fns, {x, -1, 1}, PlotStyle -> Black]] – Bob Hanlon Jan 13 '19 at 23:17
• @BobHanlon That's a good way, except that the PlotRange will be determined by the first function. Adding PlotRange -> All may help, but not if a function has a very large range compared to others. – Michael E2 Jan 14 '19 at 0:14
• @MichaelE2 - or the PlotRange can be specified as an option to Show – Bob Hanlon Jan 14 '19 at 0:16
• @BobHanlon Yeah, I meant adding PlotRange -> All to Show[] but didn't say where it was to go. – Michael E2 Jan 14 '19 at 0:18
• One could also use PadRight[]: Plot[x^Range[5] // Evaluate, {x, -1, 1}, PlotStyle -> PadRight[{Red}, 5, Black]] – J. M. will be back soon Mar 29 '19 at 15:04

Here's a way with an UpValue:

repPlotStyle /: Plot[f_, {x_, a_, b_}, o1___,
repPlotStyle[PlotStyle -> {s1 : Except[_List] ..., s2_List}],
o2___] :=
With[{n = Length[Block[{x = (a + b)/2.}, f]]},  (* could use Length[f] *)
With[{s = Take[
Join[{s1}, Apply[Join, Table[s2, {(n/ Length[s2]) + 1}]]],
n]},
Plot[f, {x, a, b}, o1, PlotStyle -> s, o2]
]];

Plot[Evaluate[ChebyshevT[Range@11, x]], {x, -1, 1},
PlotStyle -> {Red, {Black}} // repPlotStyle]


Plot[Evaluate[ChebyshevT[Range@11, x]], {x, -1, 1},
PlotStyle -> {Red, Orange, {Black, Blue, Green}} // repPlotStyle]


Or tweak an internal function in the same way (not guaranteed to work in versions other than 11.3):

InternalInheritedBlock[
Unprotect@ChartingpadList;
Protect@ChartingpadList;
`