Skip to content

Commit a4a819f

Browse files
author
Tom Augspurger
committed
Merge pull request #6850 from zachcp/histograms
DOC: add bins argument to Histogram function
2 parents d6241d8 + 8960456 commit a4a819f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

pandas/tests/test_graphics.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def test_hist(self):
110110
_check_plot_works(self.ts.hist, grid=False)
111111
_check_plot_works(self.ts.hist, figsize=(8, 10))
112112
_check_plot_works(self.ts.hist, by=self.ts.index.month)
113+
_check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5)
113114

114115
import matplotlib.pyplot as plt
115116
fig, ax = plt.subplots(1, 1)
@@ -909,6 +910,9 @@ def test_hist(self):
909910
# handle figsize arg
910911
_check_plot_works(df.hist, figsize=(8, 10))
911912

913+
# check bins argument
914+
_check_plot_works(df.hist, bins=5)
915+
912916
# make sure xlabelsize and xrot are handled
913917
ser = df[0]
914918
xf, yf = 20, 20

pandas/tools/plotting.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ def plot_group(group, ax):
22632263

22642264
def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
22652265
xrot=None, ylabelsize=None, yrot=None, ax=None, sharex=False,
2266-
sharey=False, figsize=None, layout=None, **kwds):
2266+
sharey=False, figsize=None, layout=None, bins=10, **kwds):
22672267
"""
22682268
Draw histogram of the DataFrame's series using matplotlib / pylab.
22692269
@@ -2290,6 +2290,8 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
22902290
figsize : tuple
22912291
The size of the figure to create in inches by default
22922292
layout: (optional) a tuple (rows, columns) for the layout of the histograms
2293+
bins: integer, default 10
2294+
Number of histogram bins to be used
22932295
kwds : other plotting keyword arguments
22942296
To be passed to hist function
22952297
"""
@@ -2302,7 +2304,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
23022304

23032305
if by is not None:
23042306
axes = grouped_hist(data, by=by, ax=ax, grid=grid, figsize=figsize,
2305-
sharex=sharex, sharey=sharey, layout=layout,
2307+
sharex=sharex, sharey=sharey, layout=layout, bins=bins,
23062308
**kwds)
23072309

23082310
for ax in axes.ravel():
@@ -2363,7 +2365,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
23632365

23642366

23652367
def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
2366-
xrot=None, ylabelsize=None, yrot=None, figsize=None, **kwds):
2368+
xrot=None, ylabelsize=None, yrot=None, figsize=None, bins=10, **kwds):
23672369
"""
23682370
Draw histogram of the input series using matplotlib
23692371
@@ -2385,6 +2387,8 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
23852387
rotation of y axis labels
23862388
figsize : tuple, default None
23872389
figure size in inches by default
2390+
bins: integer, default 10
2391+
Number of histogram bins to be used
23882392
kwds : keywords
23892393
To be passed to the actual plotting function
23902394
@@ -2411,7 +2415,7 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
24112415
raise AssertionError('passed axis not bound to passed figure')
24122416
values = self.dropna().values
24132417

2414-
ax.hist(values, **kwds)
2418+
ax.hist(values, bins=bins, **kwds)
24152419
ax.grid(grid)
24162420
axes = np.array([ax])
24172421
else:
@@ -2420,7 +2424,7 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
24202424
"'by' argument, since a new 'Figure' instance "
24212425
"will be created")
24222426
axes = grouped_hist(self, by=by, ax=ax, grid=grid, figsize=figsize,
2423-
**kwds)
2427+
bins=bins, **kwds)
24242428

24252429
for ax in axes.ravel():
24262430
if xlabelsize is not None:

0 commit comments

Comments
 (0)