Histogram Bar Line Thickness
The most direct and versatile way would be to generate your own chart elements. Fortunately, for rectangles this is quite easy:
data = RandomReal[{0, 100}, 1000];
Clear[thick]
thick[{{xmin_, xmax_}, {ymin_, ymax_}}, values_, metadata_] :=
{EdgeForm[Thick], Rectangle[{xmin, ymin}, {xmax, ymax}]}
Histogram[data, ChartElementFunction -> thick]
Once you decide to make your own primitives, you also gain some flexibility, e.g. by choosing to leave off the bottom edge of each bar, as requested in comments:
Clear[thickNoBottom]
thickNoBottom[{{xmin_, xmax_}, {ymin_, ymax_}}, values_, metadata_] := {
{EdgeForm[None], Rectangle[{xmin, ymin}, {xmax, ymax}]},
{Thickness[0.015], Black, CapForm["Butt"],
Line[{{xmin, ymin}, {xmin, ymax}, {xmax, ymax}, {xmax, ymin}}]}
}
Histogram[data, ChartBaseStyle -> Thick, ChartElementFunction -> thickNoBottom]
You are looking to modify the EdgeForm
of your ChartStyle
, and this is shown in the documentation for Histogram
, in the Options
section.
SeedRandom[42];
data = RandomVariate[NormalDistribution[0, 1], 200];
Histogram[data,
ChartStyle -> {EdgeForm[
Directive[AbsoluteThickness[2], Black, Opacity[1]]]}]
Update 2: Based on the accepted answer it now seems that removing the bottom of edge of rectangles is not essential. In that case, the option ChartBaseStyle
gives the desired result (there is no need for custom ChartElementFunction
s):
Histogram[data, ChartBaseStyle -> EdgeForm[Thickness[.01]]]
Histogram[data, ChartStyle -> "Pastel",
ChartElementFunction -> "GlassRectangle",
ChartBaseStyle -> EdgeForm[{Opacity[1, Red], Thickness[.01]}]]
Update: The ChartElementFunction
in the original post works only for the default setting for the option BarOrigin
. The new function ceF2
works for arbitrary values for the BarOrigin
option.
ceF2[cedf_: "GlassRectangle", o : OptionsPattern[]][col_: Black, thickness_: 3] :=
Module[{or = Charting`ChartStyleInformation["BarOrigin"], ll = Tuples[#][[{1, 2, 4, 3}]]},
ll = RotateRight[ll, Switch[or, Bottom, 0, Top, 2, Left, 3, Right, 1]] ;
{ChartElementDataFunction[cedf, o][##],
col, AbsoluteThickness[thickness], CapForm["Butt"], Line[ll]}] &
Examples:
Grid[Partition[Histogram[data, ChartStyle -> 1, ImageSize -> 300,
PlotLabel -> Style["BarOrigin -> " <> ToString[#], 16, "Panel"],
ChartElementFunction -> ceF2["FadingRectangle", "GradientOrigin" -> Top][
Dynamic[Darker@CurrentValue["Color"]], 5],
BarOrigin -> #] & /@ {Bottom, Top, Left, Right}, 2]]
Original post:
A more flexible chart element function that modifies built-in chart element functions to add thick lines:
ClearAll[ceF]
ceF[cedf_: "GlassRectangle", o : OptionsPattern[]][col_: Black, thickness_: 3] :=
{ChartElementDataFunction[cedf, o][##],
col, AbsoluteThickness[thickness], CapForm["Butt"],
Line[Tuples[#][[{1, 2, 4, 3}]]]} &
Examples:
SeedRandom[42];
data = RandomVariate[NormalDistribution[0, 1], 200];
Histogram[data, ChartStyle -> 1, ChartElementFunction -> ceF[][]]
Histogram[data, ChartStyle -> 1,
ChartElementFunction ->
ceF["FadingRectangle"][Dynamic[Darker@Darker@CurrentValue["Color"]], 5]]
Histogram[data, ChartStyle -> 1,
ChartElementFunction ->
ceF["FadingRectangle", "GradientOrigin"->Top][Dynamic[Darker@CurrentValue["Color"]], 5]]
Histogram[data, 5, ChartStyle -> {Red, Green, Blue, Orange, Cyan, Purple},
ChartElementFunction ->
ceF["FadingRectangle", "GradientOrigin"->Top][Dynamic[Darker@CurrentValue["Color"]], 5]]