# Want a different color for each curve displayed with Show

I want a different color for each curve that I am displaying with Show.

The functions are: custom1 custom2 custom3 custom4 custom5, and I am using the following code to plot these functions;

Show[
Histogram[R, Automatic, "PDF"],
Plot[Evaluate[Tooltip[PDF[#, x], #]], {x, 0, 1}] & /@
{custom1[26.99,0.17, 13, 3.58, 0.77, 45.11],
custom2[152.84, 4.89, 4.91, 0.28, 172.13],
custom3[37.75, 0.35, 1.09, 29.49],
custom4[20880.9, 0.29, 21634.8],
custom5[3.08, 5.39]}]


The graph is:

• Duplicate of this question? Commented Nov 15, 2014 at 15:16

r = RandomVariate[NormalDistribution[0, 1], 1500];
custom = NormalDistribution[#, 1] & /@ Range[0, 2, .4];
(* to be replaced with your custom1, custom2, ... *)


You can do one of several things:

Make a single Plot instead of five separate ones

Show[Histogram[r, Automatic, "PDF"],
Plot[Evaluate[Tooltip[PDF[#, x], #] & /@ custom], {x, -3, 3}]]
(* or Plot[Tooltip[PDF[#, x], #] & /@ custom, {x, -3, 3}, Evaluated -> True] *)


Or provide individual colors in each of Plots:

Show[Histogram[r, Automatic, "PDF"],
Plot[Evaluate[Tooltip[PDF[#, x], #]], {x, -3, 3},
PlotStyle -> {Thick, Hue[RandomReal[]]}] & /@ custom]


Block[{i = 1}, Show[Histogram[r, Automatic, "PDF"], With[{j = i++},
Plot[Evaluate[Tooltip[PDF[#, x], #]], {x, -3, 3},
PlotStyle -> {Thick, ColorData[63, "ColorList"][[j]]}]] & /@ custom]]


Legended[Block[{i = 1},
Show[Histogram[r, Automatic, "PDF"],
With[{j = i++}, Plot[Evaluate[Tooltip[PDF[#, x], #]], {x, -3, 3},
PlotStyle -> {Thick, ColorData[63, "ColorList"][[j]]}]] & /@ custom]],
LineLegend[ColorData[63, "ColorList"][[;; 5]],
{"custom1", "custom2", "custom3", "custom4", "custom5"}]]


Update 2: You can also put everything in a single Plot using the PDF of HistogramDistribution:

hd = HistogramDistribution[r];
custom2 = Prepend[custom, hd];
legendlabels = (Style[#, "Panel", 14] & /@ custom2 /.

Plot[Tooltip[PDF[#, x], #] & /@ custom2, {x, -3, 3},
LabelStyle -> {16, "Panel", Background -> None}, BaseStyle -> Thick,
PlotStyle -> ColorData[63, "ColorList"], Evaluated -> True, Exclusions -> False,
FillingStyle -> (Lighter@Lighter@ColorData[63, "ColorList"][[1]]),
Filling -> {1 -> Axis}, PlotLegends -> legendlabels]


Another update: Two additional methods with minimal changes in OP's code to add random colors:

Post-process the Lines to add color directives:

op = Show[Histogram[r, Automatic, "PDF"],
Plot[Evaluate[Tooltip[PDF[#, x], #]], {x, -3, 3}] & /@ custom, ImageSize -> 300];

Row[{op, op /. line : Line[__] :> {Thick, Hue[RandomReal[]], line}}, Spacer[5]]


Use Dynamic in PlotStyle options setting:

Show[Histogram[r, Automatic, "PDF"],
Plot[Evaluate[Tooltip[PDF[#, x], #]], {x, -3, 3},
PlotStyle -> Dynamic[Directive[{Thick, Hue[RandomReal[]]}]]] & /@ custom, ImageSize -> 300]
(* similar picture *)

• Thanks, The second works good, What about legend and line style?
– Momo
Commented Nov 15, 2014 at 12:29
• @Momo, please see the update re legends.
– kglr
Commented Nov 15, 2014 at 12:50