blz blz - 1 year ago 70
Python Question

Why is pandas inserting spaces in my histogram?

Example data can be found here in CSV format.

Given the following code:

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

I obtain the following figure:

enter image description here

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 Source

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)



bins : integer or array_like, optional

If 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, optional

The 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