Message Boards Message Boards

0
|
6267 Views
|
8 Replies
|
4 Total Likes
View groups...
Share
Share this post:
GROUPS:

SOLVED: Space between histogram bins

Posted 9 years ago

Hey there,

I would like to make a histogram where the bins are separated by a tiny space (for example see below). As far as I know there is no simple command in Mathematica (version 10.3) like BinSpace[space in px] which would solve my problem. Do you have any ideas, what I can do instead?

enter image description here

POSTED BY: Martin Kaller
8 Replies
Posted 9 years ago

@Alexey Popkov: Nice! That's exactly what I was looking for. Thanks a lot!!!!

@Adriano Pascoletti: It was probably just a problem with my PC. A restart helped XP. Thanks to you, too.

POSTED BY: Martin Kaller
Posted 9 years ago

@Adriano Pascoletti: I believe your code has an failure in it. The computer doesn't come to an end with his calculations...

@Alexey Popkov: Indeed the BarChart includes a spacing command, but I prefer the histogram concept to display my data. (Easier to change number of bins)

@S M Binder: That's maybe an approach, but the problem is, that the edge is not white but a brighter gray. I could imagine this comes from the new feature of version 10 with the adaptive edge style which fades out the edge as the width of the bin decreases. But I have no clue if this is not also a problem for older versions. If I change the bin numbers (from 3 to 40) the edge remains this light gray. (By the way the color of my histogram is gray. If I change the color to orange the edge is indeed light orange.)

POSTED BY: Martin Kaller
Posted 9 years ago

If you wish to work with Histogram you could define your own ChartElementFunction as follows:

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

f2[d_][{{xmin_, xmax_}, {ymin_, ymax_}}, ___] := 
 Rectangle[{xmin + d (xmax - xmin)/2, ymin}, {xmax - d (xmax - xmin)/2, ymax}]

Histogram[{data1, data2}, Automatic, "Probability", ChartElementFunction -> f2[.2]]

enter image description here

POSTED BY: Alexey Popkov

I believe your code has an failure in it. The computer doesn't come to an end with his calculations...

Why? With Mathematica 10.3 under OS X 10.11.1 I get

data = {64, 48, 94, 37, 60, 4, 55, 11, 15, 0}; Timing[
 RectangleChart[Thread[{1, data}], BarSpacing -> Medium(*Tiny,Small,
   Medium,Large*)];]

{0.023286, Null}

ChartBaseStyle -> EdgeForm[{Thick, White}] assumes a White background.

Add modifier

ChartBaseStyle -> EdgeForm[{Thick, White}]

for example

Histogram[RandomVariate[NormalDistribution[0, 1], 200], 
 ChartBaseStyle -> EdgeForm[{Thick, White}]]
POSTED BY: S M Blinder

Use RectangleChart with the option BarSpacing

data = {64, 48, 94, 37, 60, 4, 55, 11, 15, 0};

RectangleChart[ Thread[{1, data}],  BarSpacing -> Medium(* Tiny, Small, Medium, Large *)]

or with a given spacing

RectangleChart[Thread[{1, data}], BarSpacing -> 7]
Posted 9 years ago

Or alternatively one can use BarChart with option BarSpacing:

data = {64, 48, 94, 37, 60, 4, 55, 11, 15, 0};
BarChart[data, BarSpacing -> Medium (*Tiny,Small,Medium,Large*)]

plot

POSTED BY: Alexey Popkov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract