blz - 6 months ago 12

Python Question

Example data can be found here in CSV format.

Given the following code:

`figure()`

grp.vis.plot(kind='hist', alpha=.5, normed=True)

show()

I obtain the following figure:

Why is pandas inserting gaps in the figure? The values range from 0 to 7, and are all represented, so I see no reason why this should happen.

Thanks very much in advance!

Answer

Because parameter `bins`

with default value `10`

is in `hist`

:

```
grp.vis.plot(kind='hist', alpha=.5, bins=7, normed=True)
```

If omit `rwidth`

:

```
grp.vis.plot(kind='hist', alpha=.5, bins=7)
```

Docs:

bins: integer or array_like, optionalIf an integer is given, bins + 1 bin edges are returned, consistently with numpy.histogram() for numpy version >= 1.3.

Unequally spaced bins are supported if bins is a sequence.

default is 10

rwidth: scalar or None, optionalThe relative width of the bars as a fraction of the bin width. If None, automatically compute the width.

Ignored if histtype is ‘step’ or ‘stepfilled’.

Default is None

Source (Stackoverflow)

Comments