# \[?\] Plot histogram with especial bin width value?

**URL:** <https://community.wolfram.com/t/plot-histogram-with-especial-bin-width-value/14820>\
**Category:** Questions\
**Tags:** graphics-and-visualization\
**Created:** [October 8, 2019, 2:27pm UTC](https://community.wolfram.com/t/plot-histogram-with-especial-bin-width-value/14820 "2019-10-08T14:27:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghorbani](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@ghorbani](https://community.wolfram.com/u/ghorbani)\
**Post date:** [October 8, 2019, 2:27pm UTC](https://community.wolfram.com/t/plot-histogram-with-especial-bin-width-value/14820/1 "2019-10-08T14:27:11Z")

</div>

Hi,

How do I plot the histogram for each list with bin width equal 20 in the enclosed notebook?

I appreciate your help.

Regards,

 ![8067123.png](https://global.discourse-cdn.com/wolfram/original/2X/c/c1364f64f83833b974174dd5f77a028bede49566.png)

[Histogram.nb](https://community.wolfram.com/uploads/short-url/irmdlCcSM1xgNh6Pa0uLu9744yg.nb) (53.1 KB)  
[Turkey0.xlsx](https://community.wolfram.com/uploads/short-url/bYVjhnPu0LcgCUoqYy3CwXYSx4C.xlsx) (532 KB)

---

<div class="post-metadata">

**Author:** ![jbaldwinpsw](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jbaldwinpsw](https://community.wolfram.com/u/jbaldwinpsw)\
**Post date:** [October 8, 2019, 3:59pm UTC](https://community.wolfram.com/t/plot-histogram-with-especial-bin-width-value/14820/2 "2019-10-08T15:59:22Z")

</div>

I could not get the second line in your code to combine the data columns so I’m using just the data in the first column.

To get a bin width of 20, use `{20}` in the `Histogram` command:

```
Histogram[data, {20}, "PDF", PlotRange -> {{0, 500}, {0, 0.016}}]

```

 ![histogram20.png](https://global.discourse-cdn.com/wolfram/original/1X/37ed800ac2ca687cb82b6797d113a98705388ccf.png)

I’ve used the “PDF” option so that your histograms from datasets with differing numbers of observations can be compared.

With large datasets such as yours there is no reason to display a histogram. Try a more modern nonparametric density estimate.

```
skd = SmoothKernelDistribution[data, Automatic, {"Bounded", {0, \[Infinity]}, "Gaussian"}];
Plot[PDF[skd, x], {x, 0, 500}, PlotRange -> {{0, 500}, {0, 0.016}}]

```

 ![nonparametricdensity20.png](https://global.discourse-cdn.com/wolfram/original/3X/f/c/fcb52953e2683269d17e3435473db9f058c45385.png)

One of the many advantages is the ability to superimpose several nonparametric density estimates and clearly see differences and similarities of different datasets. If you overlay histograms, you get a mess.

---

<div class="post-metadata">

**Author:** ![ghorbani](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@ghorbani](https://community.wolfram.com/u/ghorbani)\
**Post date:** [October 8, 2019, 7:26pm UTC](https://community.wolfram.com/t/plot-histogram-with-especial-bin-width-value/14820/3 "2019-10-08T19:26:45Z")

</div>

Thank you Jim for the useful explain.

I included the data in Mathematica. I would like to plot four histograms for four lists with a bin width of 20 using MapIndex command.Is it possible?

[Data.nb](https://community.wolfram.com/uploads/short-url/2sfIqnmnVmLpAQmY9Ca5cPd7uJD.nb) (53 KB)

---

<div class="post-metadata">

**Author:** ![jbaldwinpsw](https://avatars.discourse-cdn.com/v4/letter/j/ee7513/32.png) [@jbaldwinpsw](https://community.wolfram.com/u/jbaldwinpsw)\
**Post date:** [October 8, 2019, 8:55pm UTC](https://community.wolfram.com/t/plot-histogram-with-especial-bin-width-value/14820/4 "2019-10-08T20:55:20Z")

</div>

I’m sure it can be done with `MapIndexed` and lots of other ways. Here’s one of those ways given that you’ve provided the 4 lists as `S1`, `S2`, `S3`, and `S4`:

```
data = {S1, S2, S3, S4};
alldata = Transpose[{data, {"1", "2", "3", "4"}}];

h = Histogram[#[[1]], {20}, "PDF", PlotRange -> {{0, 1300}, {0, 0.016}}, PlotLabel -> #[[2]]] & /@ alldata;
GraphicsRow[h, ImageSize -> 1000]

```

 ![4histograms.png](https://global.discourse-cdn.com/wolfram/original/3X/d/d/dd61d119260705b7a39ed31922205d87357f7723.png)

I’ve given all of the histogram the same `PlotRange` values to allow a comparison. However, because these are histograms and because of most of the data being mashed up near 0, comparisons are at best difficult. One approach is to overlay nonparametric densities and use a transformation of the data such as a square root transformation.

```
k = 0.5;
skd = SmoothKernelDistribution[#[[1]]^k, Automatic, {"Bounded", {0, \[Infinity]}, "Gaussian"}] & /@ alldata;
Plot[Evaluate[PDF[#, x] & /@ skd], {x, 0, 1300^k}, PlotRange -> {{0, 1300^k}, {0, Automatic}}, 
 PlotStyle -> {Red, Blue, Green, Cyan}, PlotLegends -> {1, 2, 3, 4}]

```

 ![4smoothhistograms.png](https://global.discourse-cdn.com/wolfram/original/3X/f/b/fb5e014e64b2db7a317ced0fdf00b0f2d91325b4.png)

This makes it easier to see the similarities and differences among the distributions of the 4 datasets.
