In [1]:
%matplotlib inline
from ggplot import *

scale_x_date

scale_x_date scale a continuous x-axis. Its parameters are:

  • name - axis label
  • breaks - x tick breaks
  • labels - x tick labels

  • date_format - date string formatter


In [2]:
ggplot(meat, aes('date','beef')) + \
    geom_line() + \
    scale_x_date(breaks=date_breaks('10 years'),
                 labels=date_format('%B %-d, %Y'))


Out[2]:
<ggplot: (285186569)>

In [3]:
ggplot(meat, aes(x='date', y='beef')) + \
    stat_smooth(method='loewss', span=0.2, se=False) + \
    scale_x_date("Date", breaks=date_breaks('10 years'), labels=date_format('%B %-d, %Y'))


Out[3]:
<ggplot: (274880025)>

In [4]:
ggplot(meat, aes(x='date', ymin='beef - 1000', ymax='beef + 1000')) + \
    geom_area() + \
    scale_x_date(labels=date_format("%m/%Y"))


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/Users/glamp/miniconda2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    697                 type_pprinters=self.type_printers,
    698                 deferred_pprinters=self.deferred_printers)
--> 699             printer.pretty(obj)
    700             printer.flush()
    701             return stream.getvalue()

/Users/glamp/miniconda2/lib/python2.7/site-packages/IPython/lib/pretty.pyc in pretty(self, obj)
    381                             if callable(meth):
    382                                 return meth(obj, self, cycle)
--> 383             return _default_pprint(obj, self, cycle)
    384         finally:
    385             self.end_group()

/Users/glamp/miniconda2/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _default_pprint(obj, p, cycle)
    501     if _safe_getattr(klass, '__repr__', None) not in _baseclass_reprs:
    502         # A user-provided repr. Find newlines and replace them with p.break_()
--> 503         _repr_pprint(obj, p, cycle)
    504         return
    505     p.begin_group(1, '<')

/Users/glamp/miniconda2/lib/python2.7/site-packages/IPython/lib/pretty.pyc in _repr_pprint(obj, p, cycle)
    692     """A pprint that just redirects to the normal repr function."""
    693     # Find newlines and replace them with p.break_()
--> 694     output = repr(obj)
    695     for idx,output_line in enumerate(output.splitlines()):
    696         if idx:

/Users/glamp/miniconda2/lib/python2.7/site-packages/ggplot-0.9.0-py2.7.egg/ggplot/ggplot.pyc in __repr__(self)
    101 
    102     def __repr__(self):
--> 103         self.make()
    104         # this is nice for dev but not the best for "real"
    105         # self.fig.savefig('/tmp/ggplot.png', dpi=160)

/Users/glamp/miniconda2/lib/python2.7/site-packages/ggplot-0.9.0-py2.7.egg/ggplot/ggplot.pyc in make(self)
    543                             layer.plot(ax, facetgroup, self._aes, x_levels=self.data[self._aes['x']].unique())
    544                         else:
--> 545                             layer.plot(ax, facetgroup, self._aes)
    546 
    547             self.apply_limits()

/Users/glamp/miniconda2/lib/python2.7/site-packages/ggplot-0.9.0-py2.7.egg/ggplot/geoms/geom_area.pyc in plot(self, ax, data, _aes)
     23         if is_date(x.iloc[0]):
     24             dtype = x.iloc[0].__class__
---> 25             x = np.array([i.toordinal() for i in x])
     26             ax.fill_between(x, ymin, ymax, **params)
     27             new_ticks = [dtype(i) for i in ax.get_xticks()]

NameError: global name 'np' is not defined

In [ ]:
ggplot(pageviews, aes(x='date_hour', y='pageviews')) + \
    geom_point() + \
    scale_x_date(breaks='1 month')

In [ ]: