4
$\begingroup$

How can I control the thickness of the bars (here vertical lines) in a Histogram plot? For example in the plot below (of the corresponding image: http://goo.gl/RyMpXE) I can hardly see histogram bars above 300 brightness.

Code for producing the histogram:

imageData = Flatten[ImageData[image, "Bit16"]];

Histogram[imageData, {0, 2500, 1}, Frame -> True, 
  ScalingFunctions -> "Log", PlotRange -> {{0, 2500}, {All, 10^6}}, 
  ImageSize -> 2000, 
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 40, 
    FontFamily -> "Calibri"}, 
  FrameLabel -> {{"# of Pixels", ""}, {"Brightness", ""}}];

I would like to use in my case a bin width of 1. Since one brightness value occurs above 2000 I want to be able to see the corresponding bar - which is too thin.

enter image description here

$\endgroup$
  • 2
    $\begingroup$ Wouldn't the thickness of the bars be imposed by the binning you are using? I think you might have to use wider bins to get wider bars. Or perhaps use higher-contrast colors, or a non-white background. Can you show us the code that generated your graph? $\endgroup$ – MarcoB Jan 29 '16 at 17:49
  • 1
    $\begingroup$ Adding Background -> Black makes for a more visible line (picture), although of course it does not change the width of the bin. $\endgroup$ – MarcoB Jan 29 '16 at 18:14
3
$\begingroup$

Histogram generates Rectangle objects as bars whose edges are set to be transparent. In your case the rectangles are so thin that you can thicken them simply by drawing their edges. This will apply to all bins though!

yourhistogram = Histogram[imageData, {0, 2500, 1}, Frame -> True, 
  ScalingFunctions -> "Log", 
  (* Note the modified plot range! the original one clipped the highest bars for me *)
  PlotRange -> {{0, 2500}, All}, 
  ImageSize -> 2000, 
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 40, FontFamily -> "Calibri"}, 
  FrameLabel -> {{"# of Pixels", ""}, {"Brightness", ""}}];

yourhistogram /. 
   EdgeForm[Directive[Opacity[0.]]] -> EdgeForm[{Orange, Opacity[1], Thickness[0.003]}]

Mathematica graphics

$\endgroup$
  • $\begingroup$ @mrz You are very welcome! Thank you for the accept as well. $\endgroup$ – MarcoB Jan 29 '16 at 22:33
0
$\begingroup$

You can use Histogram[{x1,x2,x3...},bspec], where bspec is bin width specification.

Simple example:

data = RandomVariate[NormalDistribution[0, 1], 200];
Histogram[data, 5]

Output:

output with bin specification

Alternatively, you could changethe presentation to see the bins better:

Simple example:

data1 = RandomVariate[NormalDistribution[0, 1], 500];
data2 = RandomVariate[NormalDistribution[3, 1/2], 500];
data3 = RandomVariate[NormalDistribution[5, 1/3], 500];

Histogram[{data1, data2, data3}, ChartStyle -> {Red, Green, Blue}]

Output: output version2

Or using PlotTheme

Simple Example:

data = RandomVariate[NormalDistribution[0, 1], 200];
Histogram[data, 5 , PlotTheme -> "Marketing"]

Output:

output version 3

Reference:

Histogram

$\endgroup$
  • $\begingroup$ I know that - my question is different ... see added information in bold above ... $\endgroup$ – mrz Jan 29 '16 at 18:14
  • $\begingroup$ @mrz the width of the bin to which you referred to as thickness is governed by the bin specification. If you insist on keeping it at 1, the only ways known to me how to make the bins more visible are specified above. I do apologise if it didn't meet your requirements. $\endgroup$ – e.doroskevic Jan 29 '16 at 18:45
  • 1
    $\begingroup$ Thank you for your help ... may be I was a little bit unclear. Sometimes an answer which does not exactly solves my question helps for an other problem. So I am always happy for each response. $\endgroup$ – mrz Jan 29 '16 at 21:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.