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?
, PlotRange -> All
to theShow[]
$\endgroup$PlotRange
recommendation, is probably the most elegant solution to this problem. You could localizep1
andp2
if you don't like having the extra global variables. Other than that, it seems short & sweet. $\endgroup$