# How can we use specific Color Scheme as PlotStyle in Plot

My objective is to use Plot with an arbitrary Color Scheme to get something like this

but I want to use any color scheme such as:

1. a build-in scheme such as Rainbow
2. or customize once such as

.

BarLegend[{{Darker@Red, Red, Lighter@Gray, Blue, Darker@Blue}, {1,
11}}, ColorFunctionScaling -> True]


Here is my try:

dats = Table[n Sin[ x], {n, 1, 11}];
plot = Plot[dats, {x, -\[Pi], \[Pi]},
ColorFunction -> ColorData["Rainbow"], Frame -> True,
ImagePadding -> 50, PlotRangeClipping -> False]


Note that it is not working as desired, each plot should have the same color but it is coloring according to the y-axis.

For the customized color scheme mentioned above cant do it, any help, please?

## Method-1

Use ParametricPlot and the tricks by @kglr (but I cann't find the original links now)

/. {(VertexColors -> None) -> VertexColors -> Automatic}

ParametricPlot[{x, n Sin[ x]}, {n, 1, 11}, {x, -π, π},
AspectRatio -> 1, ColorFunction -> (ColorData["Rainbow"][#3] &),
MeshFunctions -> {#3 &}, Mesh -> 10, PlotPoints -> 50,
PlotStyle -> None, MeshStyle -> AbsoluteThickness[2], Axes -> False,
Frame -> False] /. {(VertexColors -> None) ->
VertexColors -> Automatic}


## Method-2

Extract colors from ColorData and use PlotStyle.

Clear[dats, colors];
dats = Table[n Sin[x], {n, 1, 11}];
colors = ColorData["Rainbow"] /@ Subdivide[0, 1, 11]
plot = Plot[dats, {x, -π, π}, Frame -> True,
ImagePadding -> 50, PlotRangeClipping -> False,
PlotStyle -> colors]


• I believe It should be a more elegant way to do that using plot Aug 15, 2022 at 8:12
• Thanks a lot @cvgmt, That is EXACTLY what I was looking for Aug 15, 2022 at 8:29

Alternatively

Show[
Table[Plot[n Sin[x], {x, -\[Pi], \[Pi]},PlotStyle -> ColorData["Rainbow"][n/11]  ] , {n,1, 11}]
,PlotRange -> All]