Problem
I would like to use consecutive PlotStyle
s (e.g. from ColorData[...]
) across different Plot
/ListPlot
/ListLinePlot
commands. That is: each plot should pick colors from the list starting where the previous plot stopped.
In other words: I want
Show[
Plot[{f[x], g[x]}, ... , PlotStyle -> cs],
Plot[{h[x], i[x]}, ... , PlotStyle -> cs]
]
to be equivalent to
Plot[{f[x], g[x], h[x], i[x]}, ... , PlotStyle -> cs]
But I still want to have the same automatic color schemes for e.g. Show[Plot[...], ListPlot[...]]
.
First attempt
Since the PlotStyle -> ColorData[n]
options seems to call ColorData[n][k]
with increasing index k
, I created a wrapper to make sure that k
always increases:
ic[n0_Integer: 0, n1_Integer: 0, f_Function: Identity] :=
Module[{N0 = n0, N1 = n1},
(If[# <= N1, N0 = N0 + N1]; N1 = #; f[N0 + #]) &
]
Now
c = ic[];
Table[c[n], {n, 1, 5}]
Table[c[n], {n, 1, 5}]
returns
{1, 2, 3, 4, 5}
{6, 7, 8, 9, 10}
And I can do the same with indexed ColorDataFunction
s like so color = ic[ColorData[n][#] &]
. Repeated calls of color[1]
will return consecutive colors.
But repeated Plot[..., PlotStyle -> color]
will always restart from the beginning.
PlotStyle->color[1]
$\endgroup$ – kglr Jun 7 '19 at 9:46PlotStyle -> color[1]
will only give different colors for differentPlot[...]
calls, not for different functions within a singlePlot[...]
. $\endgroup$ – DLichti Jun 7 '19 at 10:05PlotStyle->Table[color[1],{2}]
works for both within and across plots. $\endgroup$ – kglr Jun 7 '19 at 10:16PlotStyle
option, which is one of the things I am trying to avoid. $\endgroup$ – DLichti Jun 7 '19 at 10:25