Skip to content
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

Added hist method and added auto_x argument to plot method. #35

Closed
wants to merge 1 commit into from
Closed
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
25 changes: 23 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ def _join_index(self, other, how):

return self._constructor(result_series, index=join_index)

def plot(self, kind='line', **kwds): # pragma: no cover
def plot(self, kind='line', auto_x = False, **kwds): # pragma: no cover
"""
Plot the DataFrame's series with the index on the x-axis using
matplotlib / pylab.
Expand All @@ -1764,6 +1764,8 @@ def plot(self, kind='line', **kwds): # pragma: no cover
----------
kind : {'line', 'bar', 'hist'}
Default: line for TimeSeries, hist for Series

auto_x : If True, the method will use range(len(self)) as x-axis

kwds : other plotting keyword arguments

Expand All @@ -1774,8 +1776,27 @@ def plot(self, kind='line', **kwds): # pragma: no cover
"""
from pylab import plot

if auto_x:
x = range(len(self))
else:
x = self.index

for col in _try_sort(self.columns):
plot(x, self[col].values, label=col, **kwds)

def hist(self, **kwds):
"""
Draw Histogram the DataFrame's series using matplotlib / pylab.

Parameters
----------
kwds : other plotting keyword arguments

"""
from pylab import hist

for col in _try_sort(self.columns):
plot(self.index, self[col].values, label=col, **kwds)
hist(self[col].values, label=col, **kwds)

def _get_agg_axis(self, axis_num):
if axis_num == 0:
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ def asMatrix(self, columns=None):
return _reorder_columns(values, order, columns)

def cols(self):
"""Return sorted list of frame's columns"""
"""
Return sorted list of frame's columns
"""
if self.objects is not None and len(self.objects.columns) > 0:
return list(self.columns.union(self.objects.columns))
else:
Expand Down
30 changes: 28 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ def fill(self, value=None, method='pad'):
#-------------------------------------------------------------------------------
# Miscellaneous

def plot(self, label=None, kind='line', rot=30, axes=None, style='-',
def plot(self, label=None, kind='line', auto_x = False, rot=30, axes=None, style='-',
**kwds): # pragma: no cover
"""
Plot the input series with the index on the x-axis using
Expand All @@ -906,6 +906,7 @@ def plot(self, label=None, kind='line', rot=30, axes=None, style='-',
label : label argument to provide to plot
kind : {'line', 'bar', 'hist'}
Default: line for TimeSeries, hist for Series
auto_x : if True, it will use range(len(self)) as x-axis
kwds : other plotting keyword arguments

Notes
Expand All @@ -928,7 +929,13 @@ def plot(self, label=None, kind='line', rot=30, axes=None, style='-',
axes = plt.gca()

if kind == 'line':
axes.plot(self.index, self.values, style, **kwds)
if auto_x:
x = range(len(self))
else:
x = self.index

axes.plot(x, self.values, style, **kwds)

elif kind == 'bar':
xinds = np.arange(N) + 0.25
axes.bar(xinds, self.values, 0.5, bottom=np.zeros(N), linewidth=1)
Expand All @@ -943,6 +950,25 @@ def plot(self, label=None, kind='line', rot=30, axes=None, style='-',

plt.draw_if_interactive()

def hist(self, **kwds): # pragma: no cover
"""
Draw histogram of the input series using matplotlib / pylab.

Parameters
----------

Notes
-----
See matplotlib documentation online for more on this subject

Default plot-types: TimeSeries (line), Series (bar)

Intended to be used in ipython -pylab mode
"""
import matplotlib.pyplot as plt

plt.hist(self.values)

def toCSV(self, path):
"""
Write the Series to a CSV file
Expand Down