Skip to content

add bins argument to Histogram function #6850

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pandas/tests/test_graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def test_hist(self):
_check_plot_works(self.ts.hist, grid=False)
_check_plot_works(self.ts.hist, figsize=(8, 10))
_check_plot_works(self.ts.hist, by=self.ts.index.month)
_check_plot_works(self.ts.hist, by=self.ts.index.month, bins=5)

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

# check bins argument
_check_plot_works(df.hist, bins=5)

# make sure xlabelsize and xrot are handled
ser = df[0]
xf, yf = 20, 20
Expand Down
14 changes: 9 additions & 5 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,7 @@ def plot_group(group, ax):

def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
xrot=None, ylabelsize=None, yrot=None, ax=None, sharex=False,
sharey=False, figsize=None, layout=None, **kwds):
sharey=False, figsize=None, layout=None, bins=10, **kwds):
"""
Draw histogram of the DataFrame's series using matplotlib / pylab.

Expand All @@ -2290,6 +2290,8 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,
figsize : tuple
The size of the figure to create in inches by default
layout: (optional) a tuple (rows, columns) for the layout of the histograms
bins: integer, default 10
Number of histogram bins to be used
kwds : other plotting keyword arguments
To be passed to hist function
"""
Expand All @@ -2302,7 +2304,7 @@ def hist_frame(data, column=None, by=None, grid=True, xlabelsize=None,

if by is not None:
axes = grouped_hist(data, by=by, ax=ax, grid=grid, figsize=figsize,
sharex=sharex, sharey=sharey, layout=layout,
sharex=sharex, sharey=sharey, layout=layout, bins=bins,
**kwds)

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


def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
xrot=None, ylabelsize=None, yrot=None, figsize=None, **kwds):
xrot=None, ylabelsize=None, yrot=None, figsize=None, bins=10, **kwds):
"""
Draw histogram of the input series using matplotlib

Expand All @@ -2385,6 +2387,8 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
rotation of y axis labels
figsize : tuple, default None
figure size in inches by default
bins: integer, default 10
Number of histogram bins to be used
kwds : keywords
To be passed to the actual plotting function

Expand All @@ -2411,7 +2415,7 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
raise AssertionError('passed axis not bound to passed figure')
values = self.dropna().values

ax.hist(values, **kwds)
ax.hist(values, bins=bins, **kwds)
ax.grid(grid)
axes = np.array([ax])
else:
Expand All @@ -2420,7 +2424,7 @@ def hist_series(self, by=None, ax=None, grid=True, xlabelsize=None,
"'by' argument, since a new 'Figure' instance "
"will be created")
axes = grouped_hist(self, by=by, ax=ax, grid=grid, figsize=figsize,
**kwds)
bins=bins, **kwds)

for ax in axes.ravel():
if xlabelsize is not None:
Expand Down