diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 870aefec98916..1c50583954118 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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. @@ -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 @@ -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: diff --git a/pandas/core/matrix.py b/pandas/core/matrix.py index 5abf1ddb23a70..956a77072c532 100644 --- a/pandas/core/matrix.py +++ b/pandas/core/matrix.py @@ -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: diff --git a/pandas/core/series.py b/pandas/core/series.py index 9c0815287d7c9..290a7088856c6 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -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 @@ -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 @@ -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) @@ -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