Table of Contents


In [1]:
import altair as alt
#alt.enable_mime_rendering()
# load built-in dataset as a pandas DataFrame
cars = alt.load_dataset('cars')

# Uncomment for rendering in JupyterLab & nteract
# alt.enable_mime_rendering()

alt.Chart(cars).mark_circle().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
).display()



In [2]:
from vega_datasets import data

In [9]:
source = data.seattle_temps()
source


Out[9]:
date temp
0 2010-01-01 00:00:00 39.4
1 2010-01-01 01:00:00 39.2
2 2010-01-01 02:00:00 39.0
3 2010-01-01 03:00:00 38.9
4 2010-01-01 04:00:00 38.8
5 2010-01-01 05:00:00 38.7
6 2010-01-01 06:00:00 38.7
7 2010-01-01 07:00:00 38.6
8 2010-01-01 08:00:00 38.7
9 2010-01-01 09:00:00 39.2
10 2010-01-01 10:00:00 40.1
11 2010-01-01 11:00:00 41.3
12 2010-01-01 12:00:00 42.5
13 2010-01-01 13:00:00 43.2
14 2010-01-01 14:00:00 43.5
15 2010-01-01 15:00:00 43.3
16 2010-01-01 16:00:00 42.7
17 2010-01-01 17:00:00 41.7
18 2010-01-01 18:00:00 41.2
19 2010-01-01 19:00:00 40.9
20 2010-01-01 20:00:00 40.7
21 2010-01-01 21:00:00 40.4
22 2010-01-01 22:00:00 40.2
23 2010-01-01 23:00:00 39.9
24 2010-01-02 00:00:00 39.6
25 2010-01-02 01:00:00 39.4
26 2010-01-02 02:00:00 39.3
27 2010-01-02 03:00:00 39.1
28 2010-01-02 04:00:00 39.0
29 2010-01-02 05:00:00 38.9
... ... ...
8729 2010-12-30 18:00:00 40.8
8730 2010-12-30 19:00:00 40.5
8731 2010-12-30 20:00:00 40.3
8732 2010-12-30 21:00:00 40.0
8733 2010-12-30 22:00:00 39.8
8734 2010-12-30 23:00:00 39.5
8735 2010-12-31 00:00:00 39.2
8736 2010-12-31 01:00:00 39.0
8737 2010-12-31 02:00:00 38.9
8738 2010-12-31 03:00:00 38.7
8739 2010-12-31 04:00:00 38.6
8740 2010-12-31 05:00:00 38.5
8741 2010-12-31 06:00:00 38.5
8742 2010-12-31 07:00:00 38.4
8743 2010-12-31 08:00:00 38.5
8744 2010-12-31 09:00:00 39.0
8745 2010-12-31 10:00:00 40.0
8746 2010-12-31 11:00:00 41.2
8747 2010-12-31 12:00:00 42.3
8748 2010-12-31 13:00:00 43.0
8749 2010-12-31 14:00:00 43.3
8750 2010-12-31 15:00:00 43.1
8751 2010-12-31 16:00:00 42.5
8752 2010-12-31 17:00:00 41.5
8753 2010-12-31 18:00:00 41.0
8754 2010-12-31 19:00:00 40.7
8755 2010-12-31 20:00:00 40.5
8756 2010-12-31 21:00:00 40.2
8757 2010-12-31 22:00:00 40.0
8758 2010-12-31 23:00:00 39.6

8759 rows × 2 columns


In [23]:
chart = alt.Chart(source, max_rows=10000).mark_area().encode(
    x=alt.X('date:T', timeUnit='month', axis=alt.Axis(title='Month of the year')),
    y='temp',
    row = alt.Row('date:T', timeUnit='hours')
).display()



In [11]:
chart


---------------------------------------------------------------------------
MaxRowsExceeded                           Traceback (most recent call last)
/home/saket/anaconda2/lib/python2.7/site-packages/IPython/core/formatters.pyc in __call__(self, obj)
    913             method = get_real_method(obj, self.print_method)
    914             if method is not None:
--> 915                 method()
    916                 return True
    917 

/home/saket/anaconda2/lib/python2.7/site-packages/altair/v1/api.pyc in _ipython_display_(self)
    443         from IPython.display import display
    444         from vega import VegaLite
--> 445         display(VegaLite(self.to_dict(validate_columns=True)))
    446 
    447     def display(self):

/home/saket/anaconda2/lib/python2.7/site-packages/altair/v1/api.pyc in to_dict(self, data, validate_columns)
    287             The JSON specification of the chart object.
    288         """
--> 289         dct = super(TopLevelMixin, self.clone()).to_dict(data=data, validate_columns=validate_columns)
    290         dct['$schema'] = schema.vegalite_schema_url
    291         return dct

/home/saket/anaconda2/lib/python2.7/site-packages/altair/v1/schema/_interface/jstraitlets.pyc in to_dict(self, **kwargs)
    151     def to_dict(self, **kwargs):
    152         """Output a (nested) dict encoding the contents of this instance"""
--> 153         self._finalize(**kwargs)
    154         Visitor = self._converter_registry.get('to_dict', ToDict)
    155         return Visitor().visit(self, **kwargs)

/home/saket/anaconda2/lib/python2.7/site-packages/altair/v1/api.pyc in _finalize(self, **kwargs)
    491 
    492     def _finalize(self, **kwargs):
--> 493         self._finalize_data()
    494         # data comes from wrappers, but self.data overrides this if defined
    495         if self.data is not None:

/home/saket/anaconda2/lib/python2.7/site-packages/altair/v1/api.pyc in _finalize_data(self)
    546                     "your Chart to an integer larger than the number of rows "
    547                     "in your dataset. Alternatively you could perform aggregations "
--> 548                     "or other data reductions before using it with Altair" % DEFAULT_MAX_ROWS
    549                 )
    550 

MaxRowsExceeded: Your dataset has too many rows and could take a long time to send to the frontend or to render. To override the default maximum rows (5000), set the max_rows property of your Chart to an integer larger than the number of rows in your dataset. Alternatively you could perform aggregations or other data reductions before using it with Altair
<traitlets.traitlets.Chart at 0x7f6f17124d90>

In [ ]: