Here is a modification of the custom function cedf2
that accepts a list of {from,to,color}
triples:
ClearAll[cedf3];
cedf3[args : {{_, _, _} ..}, dfltClr_: Red,thcknss_: Small,rndngrds_: 0][{{xmin_, xmax_}, {ymin_, ymax_}}, ___] :=
With[{clr = Function[{lst, xxx},
With[{pick = Pick[lst, #[[1]] < xxx <= #[[2]] & /@ lst]},
If[pick == {}, dfltClr, Last @@ pick]]][args, xmax]}, {clr,
Dynamic@EdgeForm[Directive[Thickness[thcknss], Lighter@CurrentValue["Color"]]],
Rectangle[{xmin, ymin}, {xmax, ymax}, RoundingRadius -> rndngrds]}]
(I am sure there is better/shorter way using Which
, Switch
, Piecewise
to pick the bin color instead of the clunky one above using Pick
)
Update: A cleaner version using Piecewise
:
ClearAll[cedf4];
cedf4[args : {{_, _, _} ..}, dfltClr_:Red,thcknss_:Small, rndngrds_: 3][{{xmin_, xmax_}, {ymin_, ymax_}}, ___] :=
{Piecewise[Map[{#[[3]], #[[1]] < xmax <= #[[2]]} &, args], dfltClr],
Dynamic@EdgeForm[Directive[Thickness[thcknss], Lighter@CurrentValue["Color"]]],
Rectangle[{xmin, ymin}, {xmax, ymax}, RoundingRadius -> rndngrds]}
Usage: some input data:
binsAndColors1 = Transpose@{Most@Range[0, 50], Rest@Range[0, 50],
ColorData["Atoms", "ColorList"][[;; 50]]};
binsAndColors2 = Transpose@{Most@Range[0, 50, 2], Rest@Range[0, 50, 2],
ColorData["Crayola", "ColorList"][[;; 25]]}
Histogram[RandomVariate[NormalDistribution[10, 2], 500],
ChartElementFunction -> (cedf3[binsAndColors1, Red, Medium, 3])]

Color consecutive bars with the same color:
Histogram[RandomVariate[NormalDistribution[10, 2], 500],
ChartElementFunction -> (cedf3[binsAndColors2, Red,Medium, 3])]

Alternatively, you can use ChartStyle
:
Histogram[RandomVariate[NormalDistribution[0, 1], 500],
ChartStyle -> {ColorData["Crayola", "ColorList"][[;; 70]]}]

or, to color neighboring bins with the same color:
Histogram[RandomVariate[NormalDistribution[0, 1], 500],
ChartStyle -> {Riffle[ColorData["Crayola", "ColorList"][[;; 70]],
ColorData["Crayola", "ColorList"][[;; 70]]]}]

Which[]
andSwitch[]
. $\endgroup$ – VLC Oct 11 '12 at 9:36Piecewise[]
. Look atChartStyle
as well. $\endgroup$ – J. M. will be back soon♦ Oct 11 '12 at 9:44BarChart[]
, you could have looked at the options that contained the wordsChart
orStyle
in them... $\endgroup$ – J. M. will be back soon♦ Oct 11 '12 at 9:50