# How to plot a pair of functions as solid and dashed, but a list of those pairs as different colors, in one plot?

I have a list of pairs of functions:

fns = Table[{a*x, a*x^2}, {a, 5}]

{{x, x^2}, {2 x, 2 x^2}, {3 x, 3 x^2}, {4 x, 4 x^2}, {5 x, 5 x^2}}


What I would like to do is plot it so that the two functions in each of those pairs is the same color, but the first is solid and the second is dashed, and then have each pair be a different color than the others. So for example, it might be {{{Blue, Thick},{Blue, Dashed}},{{Red, Thick},{Red, Dashed}},...}.

If I simply do Plot[fns, {x, 0, 6}, PlotStyle -> {Thick, Dashed}], it does make the first in each pair solid and the second dashed, but it also makes them different colors: I know I could solve this by relying on the fact that they will be colored in the same order in different plots, and separating the first and second elements of each pair and plotting them separately:

p1 = Plot[Evaluate@fns[[All, 1]], {x, 0, 6}, PlotStyle -> Thick];
p2 = Plot[Evaluate@fns[[All, 2]], {x, 0, 6}, PlotStyle -> Dashed];
Show[p2, p1] But this is messy, and you can actually already see that I had to use Show[] in the order p2, p1, because if I do it as p1, p2, it uses p1's smaller vertical range, which makes it different than just plotting them all together.

I know there must be a simple way but I've read the documentation for PlotStyle and searched for posts here and can't find it. How can this be done?

• I'm thinking: no. If it's any consolation, you can add , PlotRange -> All to the Show[] – Feyre Jul 21 '16 at 15:44
• @Feyre I can think of another way, basically constructing a list manually beforehand for PlotStyle, but it's also inelegant. That's good to know though, thanks. – YungHummmma Jul 21 '16 at 16:07
• I think your solution, with @Feyre's PlotRange recommendation, is probably the most elegant solution to this problem. You could localize p1 and p2 if you don't like having the extra global variables. Other than that, it seems short & sweet. – Michael E2 Jul 21 '16 at 19:25

Update

fns = Table[{a*x, a*x^2}, {a, 5}];

cd = Flatten@Table[{
Directive[ColorData[97, c], Thick],
Directive[ColorData[97, c], Dashed]
}, {c, Length[fns]}];

Plot[Evaluate@fns, {x, 0, 6}, PlotStyle -> cd, PlotRange -> All, PlotLabels -> Automatic] fns = Table[{a*x, a*x^2}, {a, 5}];

psA = Table[Directive[ColorData[97, c], Thick], {c, 5}];
psB = Table[Directive[ColorData[97, c], Dashed], {c, 5}];

Plot[{Evaluate@fns[[All, 1]], Evaluate@fns[[All, 2]]}, {x, 0, 6},
PlotStyle -> Join[psA, psB], PlotLabels -> Automatic,
PlotRange -> All] • ...or, use ColorData[1, c] (pre-version 10) or ColorData[97, c] (current version) to get the default colors. – J. M. will be back soon Jul 21 '16 at 17:09
• @YungHummmma does this work for you? – Young Jul 22 '16 at 2:07