├── altair ├── sphinxext │ └── __init__.py ├── tests │ └── __init__.py ├── examples │ ├── tests │ │ ├── __init__.py │ │ └── test_examples.py │ ├── strip_plot.py │ ├── bubble_plot.py │ ├── grouped_bar_chart.py │ ├── trellis_scatter_plot.py │ ├── trail_marker.py │ ├── layered_area_chart.py │ ├── trellis_area.py │ ├── bar_chart_horizontal.py │ ├── multiple_marks.py │ ├── simple_stacked_area_chart.py │ ├── grouped_bar_chart_horizontal.py │ ├── binned_scatterplot.py │ ├── slope_graph.py │ ├── layered_bar_chart.py │ ├── simple_bar_chart.py │ ├── simple_histogram.py │ ├── interactive_scatter_plot.py │ ├── stacked_bar_chart.py │ ├── normalized_stacked_area_chart.py │ ├── table_bubble_plot_github.py │ ├── trellis_histogram.py │ ├── line_chart_with_points.py │ ├── simple_line_chart.py │ ├── multi_series_line.py │ ├── gantt_chart.py │ ├── horizontal_stacked_bar_chart.py │ ├── line_percent.py │ ├── binned_heatmap.py │ ├── normalized_stacked_bar_chart.py │ ├── bar_chart_with_mean_line.py │ ├── bar_and_line_with_dual_axis.py │ ├── filled_step_chart.py │ ├── trellis_stacked_bar_chart.py │ ├── multifeature_scatter_plot.py │ ├── choropleth.py │ ├── stacked_bar_chart_sorted_segments.py │ ├── streamgraph.py │ ├── histogram_with_a_global_mean_overlay.py │ ├── __init__.py │ ├── bar_chart_with_negatives.py │ ├── bar_chart_with_labels.py │ ├── interactive_brush.py │ ├── bar_chart_sorted.py │ ├── scatter_tooltips.py │ ├── trellis_area_sort_array.py │ ├── simple_heatmap.py │ ├── scatter_with_labels.py │ ├── one_dot_per_zipcode.py │ ├── scatter_href.py │ ├── step_chart.py │ ├── scatter_matrix.py │ ├── anscombe_plot.py │ ├── gapminder_bubble_plot.py │ ├── percentage_of_total.py │ ├── interval_selection.py │ ├── layer_line_color_rule.py │ ├── scatter_linked_brush.py │ ├── bar_chart_with_highlighted_bar.py │ ├── cumulative_wiki_donations.py │ ├── line_with_ci.py │ ├── iowa_electricity.py │ ├── connected_scatterplot.py │ ├── natural_disasters.py │ ├── choropleth_repeat.py │ ├── weather_heatmap.py │ ├── layered_chart_bar_mark.py │ ├── bar_chart_with_highlighted_segment.py │ ├── airports.py │ ├── world_projections.py │ ├── selection_histogram.py │ ├── error_bars_with_ci.py │ ├── layered_heatmap_text.py │ ├── parallel_coordinates.py │ ├── selection_layer_bar_month.py │ ├── top_k_items.py │ ├── layered_histogram.py │ ├── multiline_highlight.py │ ├── isotype_grid.py │ ├── us_population_over_time.py │ ├── stem_and_leaf.py │ ├── axes_scales.py │ ├── boxplot_max_min.py │ ├── ranged_dot_plot.py │ ├── simple_scatter_with_errorbars.py │ ├── us_state_capitals.py │ ├── horizon_graph.py │ ├── interactive_layered_crossfilter.py │ ├── beckers_barley_trellis_plot.py │ ├── dot_dash_plot.py │ ├── poly_fit.py │ ├── interactive_cross_highlight.py │ ├── scatter_marginal_hist.py │ ├── us_employment.py │ ├── top_k_letters.py │ ├── us_population_pyramid_over_time.py │ ├── scatter_with_histogram.py │ ├── seattle_weather_interactive.py │ ├── co2_concentration.py │ ├── london_tube.py │ ├── select_detail.py │ ├── multiline_tooltip.py │ ├── falkensee.py │ ├── isotype_emoji.py │ └── multiple_interactions.py ├── expr │ ├── tests │ │ ├── __init__.py │ │ └── test_expr.py │ ├── __init__.py │ └── consts.py ├── utils │ ├── tests │ │ ├── __init__.py │ │ ├── test_server.py │ │ ├── test_execeval.py │ │ ├── test_html.py │ │ ├── test_plugin_registry.py │ │ ├── test_utils.py │ │ └── test_data.py │ ├── theme.py │ ├── _py3k_compat.py │ ├── urls.py │ ├── __init__.py │ ├── execeval.py │ └── mimebundle.py ├── vegalite │ ├── tests │ │ ├── __init__.py │ │ └── test_common.py │ ├── v2 │ │ ├── tests │ │ │ ├── __init__.py │ │ │ ├── test_display.py │ │ │ └── test_renderers.py │ │ ├── schema │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── html.py │ │ ├── theme.py │ │ └── data.py │ ├── __init__.py │ ├── api.py │ ├── schema.py │ ├── v1 │ │ ├── schema │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── html.py │ │ ├── theme.py │ │ └── data.py │ ├── display.py │ └── data.py ├── vega │ ├── __init__.py │ ├── v2 │ │ ├── schema │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── data.py │ │ └── display.py │ ├── v3 │ │ ├── schema │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── data.py │ │ └── display.py │ ├── v4 │ │ ├── schema │ │ │ └── __init__.py │ │ ├── __init__.py │ │ ├── data.py │ │ └── display.py │ ├── display.py │ └── data.py ├── __init__.py └── datasets.py ├── tools └── schemapi │ ├── tests │ ├── __init__.py │ ├── test_utils.py │ └── test_decorator.py │ ├── __init__.py │ └── decorator.py ├── images └── cars.png ├── doc ├── requirements.txt ├── _static │ ├── favicon.ico │ ├── gray-square.png │ ├── altair-logo-light.png │ ├── altair-plot.css │ ├── custom.css │ ├── theme_overrides.css │ ├── chart.html │ └── altair-gallery.css ├── .gitignore ├── _templates │ └── class.rst ├── sync_website.sh ├── getting_started │ └── overview.rst ├── user_guide │ ├── importing.rst │ ├── renderers.rst │ ├── custom_renderers.rst │ ├── ecosystem.rst │ └── marks.rst └── index.rst ├── design ├── altair-logo.png ├── altair-logo-light.png ├── altair-logo.svg └── altair-logo-light.svg ├── paper ├── seattle_weather_interactive.png └── paper.bib ├── requirements.txt ├── MANIFEST.in ├── requirements_dev.txt ├── setup.cfg ├── Makefile ├── .travis.yml ├── CONTRIBUTING.md ├── .gitignore ├── LICENSE ├── RELEASING.md ├── NOTES_FOR_MAINTAINERS.md └── setup.py /altair/sphinxext/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /altair/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /altair/examples/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /altair/expr/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /altair/utils/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /altair/vegalite/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/schemapi/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /altair/vegalite/v2/tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /altair/vega/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .v4 import * 3 | -------------------------------------------------------------------------------- /altair/vegalite/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .v2 import * 3 | -------------------------------------------------------------------------------- /altair/vegalite/api.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .v2.api import * 3 | -------------------------------------------------------------------------------- /images/cars.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/altair/master/images/cars.png -------------------------------------------------------------------------------- /doc/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx 2 | jinja2 3 | numpydoc 4 | pillow 5 | sphinx_rtd_theme 6 | -------------------------------------------------------------------------------- /design/altair-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/altair/master/design/altair-logo.png -------------------------------------------------------------------------------- /doc/_static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/altair/master/doc/_static/favicon.ico -------------------------------------------------------------------------------- /altair/vegalite/schema.py: -------------------------------------------------------------------------------- 1 | """Altair schema wrappers""" 2 | # flake8: noqa 3 | from .v2.schema import * 4 | -------------------------------------------------------------------------------- /design/altair-logo-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/altair/master/design/altair-logo-light.png -------------------------------------------------------------------------------- /doc/_static/gray-square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/altair/master/doc/_static/gray-square.png -------------------------------------------------------------------------------- /doc/_static/altair-logo-light.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/altair/master/doc/_static/altair-logo-light.png -------------------------------------------------------------------------------- /paper/seattle_weather_interactive.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/0101011/altair/master/paper/seattle_weather_interactive.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | entrypoints 2 | jinja2 3 | jsonschema 4 | numpy 5 | pandas 6 | six 7 | toolz 8 | typing>=3.6;python_version<"3.5" 9 | -------------------------------------------------------------------------------- /altair/vega/v2/schema/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .core import * 3 | 4 | SCHEMA_VERSION = 'v2.6.5' 5 | SCHEMA_URL = 'https://vega.github.io/schema/vega/v2.6.5.json' 6 | -------------------------------------------------------------------------------- /altair/vega/v3/schema/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .core import * 3 | 4 | SCHEMA_VERSION = 'v3.3.1' 5 | SCHEMA_URL = 'https://vega.github.io/schema/vega/v3.3.1.json' 6 | -------------------------------------------------------------------------------- /altair/vega/v4/schema/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .core import * 3 | 4 | SCHEMA_VERSION = 'v4.0.0' 5 | SCHEMA_URL = 'https://vega.github.io/schema/vega/v4.0.0.json' 6 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | _build 2 | 3 | # gallery is auto-generated; don't version-control it 4 | gallery 5 | _images 6 | 7 | # generated class documentation 8 | user_guide/generated 9 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include *.md 2 | include Makefile 3 | include LICENSE 4 | include CHANGES.md 5 | include requirements.txt 6 | include requirements_dev.txt 7 | recursive-include altair *.py *.json *.ipynb *.html 8 | -------------------------------------------------------------------------------- /altair/vegalite/v1/schema/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .core import * 3 | from .channels import * 4 | SCHEMA_VERSION = 'v1.3.1' 5 | SCHEMA_URL = 'https://vega.github.io/schema/vega-lite/v1.3.1.json' 6 | -------------------------------------------------------------------------------- /altair/vegalite/v2/schema/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .core import * 3 | from .channels import * 4 | SCHEMA_VERSION = 'v2.6.0' 5 | SCHEMA_URL = 'https://vega.github.io/schema/vega-lite/v2.6.0.json' 6 | -------------------------------------------------------------------------------- /altair/expr/__init__.py: -------------------------------------------------------------------------------- 1 | """Tools for creating transform & filter expressions with a python syntax""" 2 | # flake8: noqa 3 | from .core import datum, Expression 4 | from .funcs import * 5 | from .consts import * 6 | -------------------------------------------------------------------------------- /doc/_static/altair-plot.css: -------------------------------------------------------------------------------- 1 | .vega-actions a { 2 | margin-right: 12px; 3 | color: #757575; 4 | font-weight: normal; 5 | font-size: 13px; 6 | } 7 | 8 | .vega-embed { 9 | margin-bottom: 20px; 10 | margin-top: 20px; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /altair/vega/v2/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .display import vega, Vega, renderers 3 | from .schema import * 4 | 5 | from .data import ( 6 | pipe, curry, limit_rows, 7 | sample, to_json, to_csv, to_values, 8 | default_data_transformer 9 | ) 10 | -------------------------------------------------------------------------------- /altair/vega/v3/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .display import vega, Vega, renderers 3 | from .schema import * 4 | 5 | from .data import ( 6 | pipe, curry, limit_rows, 7 | sample, to_json, to_csv, to_values, 8 | default_data_transformer 9 | ) 10 | -------------------------------------------------------------------------------- /altair/vega/v4/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .display import vega, Vega, renderers 3 | from .schema import * 4 | 5 | from .data import ( 6 | pipe, curry, limit_rows, 7 | sample, to_json, to_csv, to_values, 8 | default_data_transformer 9 | ) 10 | -------------------------------------------------------------------------------- /altair/utils/theme.py: -------------------------------------------------------------------------------- 1 | """Utilities for registering and working with themes""" 2 | 3 | from .plugin_registry import PluginRegistry 4 | from typing import Callable 5 | 6 | ThemeType = Callable[..., dict] 7 | 8 | class ThemeRegistry(PluginRegistry[ThemeType]): 9 | pass 10 | -------------------------------------------------------------------------------- /requirements_dev.txt: -------------------------------------------------------------------------------- 1 | flake8 2 | pytest 3 | sphinx 4 | m2r 5 | docutils 6 | vega_datasets 7 | recommonmark 8 | 9 | 10 | ipython<6; python_version < '3' # ipython 6 not compatible with python 2 11 | ipython; python_version >= '3' # ipython 6 not compatible with python 2 12 | -------------------------------------------------------------------------------- /altair/utils/_py3k_compat.py: -------------------------------------------------------------------------------- 1 | import six 2 | 3 | 4 | if six.PY2: 5 | import BaseHTTPServer as server 6 | from StringIO import StringIO as IO 7 | else: 8 | from http import server 9 | from io import BytesIO as IO 10 | 11 | 12 | __all__ = ( 13 | "server", 14 | "IO" 15 | ) 16 | -------------------------------------------------------------------------------- /altair/utils/tests/test_server.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test http server 3 | """ 4 | 5 | from altair.utils.server import serve, MockServer 6 | 7 | 8 | def test_serve(): 9 | html = '
Content
' 10 | serve(html, open_browser=False, http_server=MockServer) 11 | -------------------------------------------------------------------------------- /doc/_templates/class.rst: -------------------------------------------------------------------------------- 1 | :mod:`{{module}}`.{{objname}} 2 | {{ underline }}============== 3 | 4 | .. currentmodule:: {{ module }} 5 | 6 | .. autoclass:: {{ objname }} 7 | 8 | {% block methods %} 9 | .. automethod:: __init__ 10 | {% endblock %} 11 | 12 | .. raw:: html 13 | 14 | 15 | -------------------------------------------------------------------------------- /altair/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | __version__ = '2.5.0dev0' 3 | 4 | from .vegalite import * 5 | from . import examples 6 | 7 | def load_ipython_extension(ipython): 8 | from ._magics import vega, vegalite 9 | ipython.register_magic_function(vega, 'cell') 10 | ipython.register_magic_function(vegalite, 'cell') 11 | -------------------------------------------------------------------------------- /altair/utils/urls.py: -------------------------------------------------------------------------------- 1 | D3_JS_URL = "https://d3js.org/d3.v3.min.js" 2 | VEGA_JS_URL = "https://cdnjs.cloudflare.com/ajax/libs/vega/2.6.5/vega.min.js" 3 | VEGALITE_JS_URL = "https://cdnjs.cloudflare.com/ajax/libs/vega-lite/1.2.1/vega-lite.min.js" 4 | VEGAEMBED_JS_URL = "https://cdnjs.cloudflare.com/ajax/libs/vega-embed/2.2.0/vega-embed.min.js" 5 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = 3 | E # Ignore all PEP8 rules 4 | W # Ignore all whitespace rules 5 | F811 # Ignore variable redefinitions until https://github.com/altair-viz/altair/issues/734 is resolved 6 | 7 | [metadata] 8 | description-file = README.md 9 | license_file = LICENSE 10 | 11 | [bdist_wheel] 12 | universal = 1 -------------------------------------------------------------------------------- /altair/vegalite/display.py: -------------------------------------------------------------------------------- 1 | from ..utils.display import Displayable, default_renderer_base, json_renderer_base 2 | from ..utils.display import RendererRegistry, HTMLRenderer 3 | 4 | 5 | __all__ = ( 6 | "Displayable", 7 | "default_renderer_base", 8 | "json_renderer_base", 9 | "RendererRegistry", 10 | "HTMLRenderer", 11 | ) 12 | -------------------------------------------------------------------------------- /tools/schemapi/__init__.py: -------------------------------------------------------------------------------- 1 | """ 2 | schemapi: tools for generating Python APIs from JSON schemas 3 | """ 4 | from .schemapi import SchemaBase, Undefined 5 | from .decorator import schemaclass 6 | from .utils import SchemaInfo 7 | 8 | 9 | __all__ = ( 10 | "SchemaBase", 11 | "Undefined", 12 | "schemaclass", 13 | "SchemaInfo" 14 | ) 15 | -------------------------------------------------------------------------------- /altair/examples/strip_plot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Strip Plot 3 | ----------------- 4 | A simple example of how to make a strip plot. 5 | """ 6 | # category: simple charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.cars() 11 | 12 | alt.Chart(source).mark_tick().encode( 13 | x='Horsepower:Q', 14 | y='Cylinders:O' 15 | ) 16 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: install 2 | 3 | install: 4 | python setup.py install 5 | 6 | test : 7 | python -m pytest --pyargs --doctest-modules altair 8 | 9 | test-coverage: 10 | python -m pytest --pyargs --doctest-modules --cov=altair --cov-report term altair 11 | 12 | test-coverage-html: 13 | python -m pytest --pyargs --doctest-modules --cov=altair --cov-report html altair 14 | -------------------------------------------------------------------------------- /altair/vega/display.py: -------------------------------------------------------------------------------- 1 | from ..utils.display import Displayable, default_renderer_base, json_renderer_base 2 | from ..utils.display import MimeBundleType, RendererType, HTMLRenderer 3 | 4 | 5 | __all__ = ( 6 | "Displayable", 7 | "default_renderer_base", 8 | "json_renderer_base", 9 | "MimeBundleType", 10 | "RendererType", 11 | "HTMLRenderer", 12 | ) 13 | -------------------------------------------------------------------------------- /altair/examples/bubble_plot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Bubble Plot 3 | ----------------- 4 | This example shows how to make a bubble plot. 5 | """ 6 | # category: scatter plots 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.cars() 11 | 12 | alt.Chart(source).mark_point().encode( 13 | x='Horsepower', 14 | y='Miles_per_Gallon', 15 | size='Acceleration' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/grouped_bar_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Grouped Bar Chart 3 | ----------------- 4 | This example shows a grouped bar chart. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x='year:O', 14 | y='sum(yield):Q', 15 | color='year:N', 16 | column='site:N' 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/trellis_scatter_plot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Trellis Scatter Plot 3 | ----------------------- 4 | This example shows how to make a trellis scatter plot. 5 | """ 6 | # category: scatter plots 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.cars() 11 | 12 | alt.Chart(source).mark_point().encode( 13 | x='Horsepower:Q', 14 | y='Miles_per_Gallon:Q', 15 | row='Origin:N' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/trail_marker.py: -------------------------------------------------------------------------------- 1 | """ 2 | Line Chart with Varying Size 3 | ---------------------------- 4 | This is example of using the ``trail`` marker to vary the size of a line. 5 | """ 6 | # category: line charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.wheat() 11 | 12 | alt.Chart(source).mark_trail().encode( 13 | x='year:T', 14 | y='wheat:Q', 15 | size='wheat:Q' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/layered_area_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Layered Area Chart 3 | ------------------ 4 | This example shows a layered area chart. 5 | """ 6 | # category: area charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.iowa_electricity() 11 | 12 | alt.Chart(source).mark_area(opacity=0.3).encode( 13 | x="year:T", 14 | y=alt.Y("net_generation:Q", stack=None), 15 | color="source:N" 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/trellis_area.py: -------------------------------------------------------------------------------- 1 | """ 2 | Trellis Area Chart 3 | ------------------ 4 | This example shows small multiples of an area chart. 5 | """ 6 | # category: area charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.iowa_electricity() 11 | 12 | alt.Chart(source).mark_area().encode( 13 | x="year:T", 14 | y="net_generation:Q", 15 | color="source:N", 16 | row="source:N" 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/bar_chart_horizontal.py: -------------------------------------------------------------------------------- 1 | """ 2 | Horizontal Bar Chart 3 | -------------------- 4 | This example is a bar chart drawn horizontally by putting the quantitative value on the x axis. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.wheat() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x='wheat:Q', 14 | y="year:O" 15 | ).properties(height=700) 16 | -------------------------------------------------------------------------------- /altair/examples/multiple_marks.py: -------------------------------------------------------------------------------- 1 | """ 2 | Multiple Marks 3 | ============== 4 | This example demonstrates creating a single chart with multiple markers 5 | representing the same data. 6 | """ 7 | # category: other charts 8 | import altair as alt 9 | from vega_datasets import data 10 | 11 | source = data.stocks() 12 | 13 | alt.Chart(source).mark_line(point=True).encode( 14 | x='date:T', 15 | y='price:Q', 16 | color='symbol:N' 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/simple_stacked_area_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Stacked Area Chart 3 | ------------------------- 4 | This example shows how to make a simple stacked area chart. 5 | """ 6 | # category: simple charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.iowa_electricity() 11 | 12 | alt.Chart(source).mark_area().encode( 13 | x="year:T", 14 | y="net_generation:Q", 15 | color="source:N" 16 | ) 17 | -------------------------------------------------------------------------------- /doc/_static/custom.css: -------------------------------------------------------------------------------- 1 | .wy-nav-side p.caption { 2 | color: #F5F5F5; 3 | } 4 | 5 | div.wy-side-nav-search { 6 | background: #757575; 7 | } 8 | 9 | div.wy-side-nay { 10 | background: #212121; 11 | } 12 | 13 | table.field-list td li { 14 | line-height: 18px; 15 | } 16 | 17 | table.docutils td p { 18 | font-size: 14px !important; 19 | margin-bottom: 6px; 20 | 21 | } 22 | 23 | table.docutils td li { 24 | line-height: 18px; 25 | 26 | } -------------------------------------------------------------------------------- /altair/examples/grouped_bar_chart_horizontal.py: -------------------------------------------------------------------------------- 1 | """ 2 | Horizontal Grouped Bar Chart 3 | ---------------------------- 4 | This example shows a horizontal grouped bar chart. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x='sum(yield):Q', 14 | y='year:O', 15 | color='year:N', 16 | row='site:N' 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/binned_scatterplot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Binned Scatterplot 3 | ------------------ 4 | This example shows how to make a binned scatterplot. 5 | """ 6 | # category: scatter plots 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.movies.url 11 | 12 | alt.Chart(source).mark_circle().encode( 13 | alt.X('IMDB_Rating:Q', bin=True), 14 | alt.Y('Rotten_Tomatoes_Rating:Q', bin=True), 15 | size='count()' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/slope_graph.py: -------------------------------------------------------------------------------- 1 | """ 2 | Slope Graph 3 | ----------------------- 4 | This example shows how to make Slope Graph. 5 | """ 6 | # category: line charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_line().encode( 13 | x='year:O', # When using datetime values, ordinal encoding is crucial to get the right look. 14 | y='median(yield)', 15 | color='site' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/vegalite/v1/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .schema import * 3 | from .api import * 4 | 5 | from ...datasets import ( 6 | list_datasets, 7 | load_dataset 8 | ) 9 | 10 | from .. import expr 11 | 12 | from .display import VegaLite, renderers 13 | 14 | from .data import ( 15 | MaxRowsError, 16 | pipe, curry, limit_rows, 17 | sample, to_json, to_csv, to_values, 18 | default_data_transformer, 19 | data_transformers 20 | ) 21 | -------------------------------------------------------------------------------- /altair/examples/layered_bar_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Layered Bar Chart 3 | ----------------- 4 | This example shows a segmented bar chart that is layered rather than stacked. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.iowa_electricity() 11 | 12 | alt.Chart(source).mark_bar(opacity=0.7).encode( 13 | x='year:O', 14 | y=alt.Y('net_generation:Q', stack=None), 15 | color="source", 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/simple_bar_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Bar Chart 3 | ================ 4 | This example shows a basic bar chart created with Altair. 5 | """ 6 | # category: simple charts 7 | import altair as alt 8 | import pandas as pd 9 | 10 | source = pd.DataFrame({ 11 | 'a': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'], 12 | 'b': [28, 55, 43, 91, 81, 53, 19, 87, 52] 13 | }) 14 | 15 | alt.Chart(source).mark_bar().encode( 16 | x='a', 17 | y='b' 18 | ) 19 | -------------------------------------------------------------------------------- /altair/examples/simple_histogram.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Histogram 3 | ---------------- 4 | This example shows how to make a basic histogram, based on the vega-lite docs 5 | https://vega.github.io/vega-lite/examples/histogram.html 6 | """ 7 | # category: simple charts 8 | import altair as alt 9 | from vega_datasets import data 10 | 11 | source = data.movies.url 12 | 13 | alt.Chart(source).mark_bar().encode( 14 | alt.X("IMDB_Rating:Q", bin=True), 15 | y='count()', 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/interactive_scatter_plot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Interactive Colored Scatterplot 3 | -------------------------------------- 4 | This example shows how to make an interactive scatterplot. 5 | """ 6 | # category: interactive charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.cars() 11 | 12 | alt.Chart(source).mark_circle().encode( 13 | x='Horsepower', 14 | y='Miles_per_Gallon', 15 | color='Origin' 16 | ).interactive() 17 | -------------------------------------------------------------------------------- /altair/examples/stacked_bar_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Stacked Bar Chart 3 | ----------------- 4 | 5 | This is an example of a stacked bar chart using data which contains crop yields over different regions and different years in the 1930s. 6 | """ 7 | # category: bar charts 8 | import altair as alt 9 | from vega_datasets import data 10 | 11 | source = data.barley() 12 | 13 | alt.Chart(source).mark_bar().encode( 14 | x='variety', 15 | y='sum(yield)', 16 | color='site' 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/normalized_stacked_area_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Normalized Stacked Area Chart 3 | ----------------------------- 4 | This example shows how to make a normalized stacked area chart. 5 | """ 6 | # category: area charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.iowa_electricity() 11 | 12 | alt.Chart(source).mark_area().encode( 13 | x="year:T", 14 | y=alt.Y("net_generation:Q", stack="normalize"), 15 | color="source:N" 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/table_bubble_plot_github.py: -------------------------------------------------------------------------------- 1 | """ 2 | Table Bubble Plot (Github Punch Card) 3 | ------------------------------------- 4 | This example shows github contributions by the day of week and hour of the day. 5 | """ 6 | # category: scatter plots 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.github.url 11 | 12 | alt.Chart(source).mark_circle().encode( 13 | x='hours(time):O', 14 | y='day(time):O', 15 | size='sum(count):Q' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/trellis_histogram.py: -------------------------------------------------------------------------------- 1 | """ 2 | Trellis Histogram 3 | ----------------- 4 | This example shows how to make a basic trellis histogram. 5 | https://vega.github.io/vega-lite/examples/trellis_bar_histogram.html 6 | """ 7 | # category: histograms 8 | import altair as alt 9 | from vega_datasets import data 10 | 11 | source = data.cars() 12 | 13 | alt.Chart(source).mark_bar().encode( 14 | alt.X("Horsepower:Q", bin=True), 15 | y='count()', 16 | row='Origin' 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/line_chart_with_points.py: -------------------------------------------------------------------------------- 1 | """ 2 | Line Chart with Points 3 | ---------------------- 4 | This chart shows a simple line chart with points marking each value. 5 | """ 6 | # category: line charts 7 | import altair as alt 8 | import numpy as np 9 | import pandas as pd 10 | 11 | x = np.arange(100) 12 | source = pd.DataFrame({ 13 | 'x': x, 14 | 'f(x)': np.sin(x / 5)} 15 | ) 16 | 17 | alt.Chart(source).mark_line(point=True).encode( 18 | x='x', 19 | y='f(x)' 20 | ) 21 | -------------------------------------------------------------------------------- /altair/examples/simple_line_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Line Chart 3 | ----------------- 4 | This chart shows the most basic line chart, made from a dataframe with two 5 | columns. 6 | """ 7 | # category: simple charts 8 | 9 | import altair as alt 10 | import numpy as np 11 | import pandas as pd 12 | 13 | x = np.arange(100) 14 | source = pd.DataFrame({ 15 | 'x': x, 16 | 'f(x)': np.sin(x / 5)} 17 | ) 18 | 19 | alt.Chart(source).mark_line().encode( 20 | x='x', 21 | y='f(x)' 22 | ) 23 | -------------------------------------------------------------------------------- /altair/vegalite/v2/__init__.py: -------------------------------------------------------------------------------- 1 | # flake8: noqa 2 | from .schema import * 3 | from .api import * 4 | 5 | from ...datasets import ( 6 | list_datasets, 7 | load_dataset 8 | ) 9 | 10 | from ... import expr 11 | from ...expr import datum 12 | 13 | from .display import VegaLite, renderers 14 | 15 | from .data import ( 16 | MaxRowsError, 17 | pipe, curry, limit_rows, 18 | sample, to_json, to_csv, to_values, 19 | default_data_transformer, 20 | data_transformers 21 | ) 22 | -------------------------------------------------------------------------------- /altair/examples/multi_series_line.py: -------------------------------------------------------------------------------- 1 | """ 2 | Multi Series Line Chart 3 | ----------------------- 4 | 5 | This example shows how to make a multi series line chart of the daily closing stock prices for AAPL, AMZN, GOOG, IBM, and MSFT between 2000 and 2010. 6 | """ 7 | # category: line charts 8 | import altair as alt 9 | from vega_datasets import data 10 | 11 | source = data.stocks() 12 | 13 | alt.Chart(source).mark_line().encode( 14 | x='date', 15 | y='price', 16 | color='symbol' 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/gantt_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Gantt Chart 3 | ----------------- 4 | This example shows how to make a simple Gantt chart. 5 | """ 6 | # category: other charts 7 | import altair as alt 8 | import pandas as pd 9 | 10 | source = pd.DataFrame([ 11 | {"task": "A", "start": 1, "end": 3}, 12 | {"task": "B", "start": 3, "end": 8}, 13 | {"task": "C", "start": 8, "end": 10} 14 | ]) 15 | 16 | alt.Chart(source).mark_bar().encode( 17 | x='start', 18 | x2='end', 19 | y='task' 20 | ) 21 | -------------------------------------------------------------------------------- /altair/examples/horizontal_stacked_bar_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Horizontal Stacked Bar Chart 3 | ============================ 4 | This is an example of a horizontal stacked bar chart using data which contains crop yields over different regions and different years in the 1930s. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x='sum(yield)', 14 | y='variety', 15 | color='site' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/vegalite/v1/html.py: -------------------------------------------------------------------------------- 1 | HTML_TEMPLATE = """ 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | """ 19 | -------------------------------------------------------------------------------- /altair/vegalite/v2/html.py: -------------------------------------------------------------------------------- 1 | HTML_TEMPLATE = """ 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | """ 19 | -------------------------------------------------------------------------------- /altair/examples/line_percent.py: -------------------------------------------------------------------------------- 1 | """ 2 | Line Chart with Percent axis 3 | ---------------------------- 4 | This example shows how to format the tick labels of the y-axis of a chart as percentages. 5 | """ 6 | # category: line charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.jobs.url 11 | 12 | alt.Chart(source).mark_line().encode( 13 | alt.X('year:O'), 14 | alt.Y('perc:Q', axis=alt.Axis(format='%')), 15 | color='sex:N' 16 | ).transform_filter( 17 | alt.datum.job == 'Welder' 18 | ) 19 | -------------------------------------------------------------------------------- /altair/examples/binned_heatmap.py: -------------------------------------------------------------------------------- 1 | """ 2 | Binned Heatmap 3 | -------------- 4 | This example shows how to make a heatmap from binned quantitative data. 5 | """ 6 | # category: other charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.movies.url 11 | 12 | alt.Chart(source).mark_rect().encode( 13 | alt.X('IMDB_Rating:Q', bin=alt.Bin(maxbins=60)), 14 | alt.Y('Rotten_Tomatoes_Rating:Q', bin=alt.Bin(maxbins=40)), 15 | alt.Color('count(IMDB_Rating):Q', scale=alt.Scale(scheme='greenblue')) 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/normalized_stacked_bar_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Normalized Stacked Bar Chart 3 | ---------------------------- 4 | This is an example of a normalized stacked bar chart using data which contains crop yields over different regions and different years in the 1930s. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x=alt.X('sum(yield)', stack="normalize"), 14 | y='variety', 15 | color='site' 16 | ) 17 | -------------------------------------------------------------------------------- /altair/examples/bar_chart_with_mean_line.py: -------------------------------------------------------------------------------- 1 | """ 2 | Bar Chart with Line at Mean 3 | --------------------------- 4 | This example shows the mean value overlayed on a bar chart. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.wheat() 11 | 12 | bar = alt.Chart(source).mark_bar().encode( 13 | x='year:O', 14 | y='wheat:Q' 15 | ) 16 | 17 | rule = alt.Chart(source).mark_rule(color='red').encode( 18 | y='mean(wheat):Q' 19 | ) 20 | 21 | (bar + rule).properties(width=600) 22 | -------------------------------------------------------------------------------- /altair/examples/bar_and_line_with_dual_axis.py: -------------------------------------------------------------------------------- 1 | """ 2 | Bar Chart with Line on Dual Axis 3 | -------------------------------- 4 | This example shows how to combine two plots and keep their axes. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.wheat() 11 | 12 | base = alt.Chart(source).encode(x='year:O') 13 | 14 | bar = base.mark_bar().encode(y='wheat:Q') 15 | 16 | line = base.mark_line(color='red').encode( 17 | y='wages:Q' 18 | ) 19 | 20 | (bar + line).properties(width=600) 21 | -------------------------------------------------------------------------------- /altair/examples/filled_step_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Filled Step Chart 3 | ----------------- 4 | This example shows Google's stock price over time as a step chart with its area filled in and its line emphasized. 5 | """ 6 | # category: line charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.stocks() 11 | 12 | alt.Chart(source).mark_area( 13 | color="lightblue", 14 | interpolate='step-after', 15 | line=True 16 | ).encode( 17 | x='date', 18 | y='price' 19 | ).transform_filter(alt.datum.symbol == 'GOOG') 20 | -------------------------------------------------------------------------------- /altair/examples/trellis_stacked_bar_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Trellis Stacked Bar Chart 3 | ========================= 4 | This is an example of a horizontal stacked bar chart using data which contains crop yields over different regions and different years in the 1930s. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | column='year', 14 | x='sum(yield)', 15 | y='variety', 16 | color='site' 17 | ).properties(width=250) 18 | -------------------------------------------------------------------------------- /altair/examples/multifeature_scatter_plot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Multifeature Scatter Plot 3 | ========================= 4 | This example shows how to make a scatter plot with multiple feature encodings. 5 | """ 6 | # category: scatter plots 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.iris() 11 | 12 | alt.Chart(source).mark_circle().encode( 13 | alt.X('sepalLength', scale=alt.Scale(zero=False)), 14 | alt.Y('sepalWidth', scale=alt.Scale(zero=False, padding=1)), 15 | color='species', 16 | size='petalWidth' 17 | ) 18 | -------------------------------------------------------------------------------- /altair/examples/choropleth.py: -------------------------------------------------------------------------------- 1 | """ 2 | Choropleth Map 3 | ============== 4 | A choropleth map of unemployment rate per county in the US 5 | """ 6 | # category: maps 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | counties = alt.topo_feature(data.us_10m.url, 'counties') 11 | source = data.unemployment.url 12 | 13 | alt.Chart(counties).mark_geoshape().encode( 14 | color='rate:Q' 15 | ).transform_lookup( 16 | lookup='id', 17 | from_=alt.LookupData(source, 'id', ['rate']) 18 | ).project( 19 | type='albersUsa' 20 | ).properties( 21 | width=500, 22 | height=300 23 | ) 24 | -------------------------------------------------------------------------------- /altair/vega/v2/data.py: -------------------------------------------------------------------------------- 1 | from ..data import (MaxRowsError, curry, default_data_transformer, limit_rows, 2 | pipe, sample, to_csv, to_json, to_values) 3 | 4 | 5 | # ============================================================================== 6 | # Vega 2 data transformers 7 | # ============================================================================== 8 | 9 | 10 | __all__ = ( 11 | 'MaxRowsError', 12 | 'curry', 13 | 'default_data_transformer', 14 | 'limit_rows', 15 | 'pipe', 16 | 'sample', 17 | 'to_csv', 18 | 'to_json', 19 | 'to_values', 20 | ) 21 | -------------------------------------------------------------------------------- /altair/vega/v3/data.py: -------------------------------------------------------------------------------- 1 | from ..data import (MaxRowsError, curry, default_data_transformer, limit_rows, 2 | pipe, sample, to_csv, to_json, to_values) 3 | 4 | 5 | # ============================================================================== 6 | # Vega 3 data transformers 7 | # ============================================================================== 8 | 9 | 10 | __all__ = ( 11 | 'MaxRowsError', 12 | 'curry', 13 | 'default_data_transformer', 14 | 'limit_rows', 15 | 'pipe', 16 | 'sample', 17 | 'to_csv', 18 | 'to_json', 19 | 'to_values', 20 | ) 21 | -------------------------------------------------------------------------------- /altair/vega/v4/data.py: -------------------------------------------------------------------------------- 1 | from ..data import (MaxRowsError, curry, default_data_transformer, limit_rows, 2 | pipe, sample, to_csv, to_json, to_values) 3 | 4 | 5 | # ============================================================================== 6 | # Vega 3 data transformers 7 | # ============================================================================== 8 | 9 | 10 | __all__ = ( 11 | 'MaxRowsError', 12 | 'curry', 13 | 'default_data_transformer', 14 | 'limit_rows', 15 | 'pipe', 16 | 'sample', 17 | 'to_csv', 18 | 'to_json', 19 | 'to_values', 20 | ) 21 | -------------------------------------------------------------------------------- /altair/vegalite/v1/theme.py: -------------------------------------------------------------------------------- 1 | """Tools for enabling and registering chart themes""" 2 | 3 | from ...utils.theme import ThemeRegistry 4 | 5 | # The entry point group that can be used by other packages to declare other 6 | # renderers that will be auto-detected. Explicit registration is also 7 | # allowed by the PluginRegistery API. 8 | ENTRY_POINT_GROUP = 'altair.vegalite.v1.theme' # type: str 9 | 10 | themes = ThemeRegistry(entry_point_group=ENTRY_POINT_GROUP) 11 | 12 | themes.register('default', lambda: {"width": 400, "height": 300}) 13 | themes.register('none', lambda: {}) 14 | themes.enable('default') 15 | -------------------------------------------------------------------------------- /altair/examples/stacked_bar_chart_sorted_segments.py: -------------------------------------------------------------------------------- 1 | """ 2 | Stacked Bar Chart with Sorted Segments 3 | -------------------------------------- 4 | This is an example of a stacked-bar chart with the segments of each bar resorted. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x='sum(yield)', 14 | y='variety', 15 | color='site', 16 | order=alt.Order( 17 | # Sort the segments of the bars by this field 18 | 'site', 19 | sort='ascending' 20 | ) 21 | ) 22 | -------------------------------------------------------------------------------- /altair/examples/streamgraph.py: -------------------------------------------------------------------------------- 1 | """ 2 | Streamgraph 3 | ----------------- 4 | This example shows the streamgraph from vega-lite examples. 5 | """ 6 | # category: area charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.unemployment_across_industries.url 11 | 12 | alt.Chart(source).mark_area().encode( 13 | alt.X('yearmonth(date):T', 14 | axis=alt.Axis(format='%Y', domain=False, tickSize=0) 15 | ), 16 | alt.Y('sum(count):Q', stack='center', axis=None), 17 | alt.Color('series:N', 18 | scale=alt.Scale(scheme='category20b') 19 | ) 20 | ).interactive() 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | cache: pip 4 | 5 | # Enable 3.7 without globally enabling sudo and xenial 6 | matrix: 7 | include: 8 | - python: 2.7 9 | - python: 3.5 10 | - python: 3.6 11 | - python: 3.7 12 | dist: xenial 13 | sudo: true 14 | 15 | env: 16 | global: 17 | - TEST_DIR=/tmp/_altair/ 18 | 19 | before_install: 20 | - pip install pip --upgrade; 21 | - pip install -U pytest; 22 | 23 | install: 24 | - pip install -e .[dev]; 25 | 26 | script: 27 | - flake8 ./; 28 | - mkdir -p $TEST_DIR 29 | - cd $TEST_DIR && python -m pytest --pyargs --doctest-modules altair; 30 | -------------------------------------------------------------------------------- /altair/examples/histogram_with_a_global_mean_overlay.py: -------------------------------------------------------------------------------- 1 | """ 2 | Histogram with a Global Mean Overlay 3 | ------------------------------------ 4 | This example shows a histogram with a global mean overlay. 5 | """ 6 | # category: histograms 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.movies.url 11 | 12 | base = alt.Chart(source) 13 | 14 | bar = base.mark_bar().encode( 15 | x=alt.X('IMDB_Rating:Q', bin=True, axis=None), 16 | y='count()' 17 | ) 18 | 19 | rule = base.mark_rule(color='red').encode( 20 | x='mean(IMDB_Rating):Q', 21 | size=alt.value(5) 22 | ) 23 | 24 | bar + rule 25 | -------------------------------------------------------------------------------- /altair/examples/__init__.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | 4 | def iter_examples(): 5 | """Iterate over the examples in this directory. 6 | 7 | Each item is a dict with the following keys: 8 | - "name" : the unique name of the example 9 | - "filename" : the full file path to the example 10 | """ 11 | example_dir = os.path.abspath(os.path.dirname(__file__)) 12 | for filename in os.listdir(example_dir): 13 | name, ext = os.path.splitext(filename) 14 | if name.startswith('_') or ext != '.py': 15 | continue 16 | yield {'name': name, 17 | 'filename': os.path.join(example_dir, filename)} 18 | -------------------------------------------------------------------------------- /altair/examples/bar_chart_with_negatives.py: -------------------------------------------------------------------------------- 1 | """ 2 | Bar Chart with Negative Values 3 | ============================== 4 | This example shows a bar chart with both positive and negative values. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.us_employment() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x="month:T", 14 | y="nonfarm_change:Q", 15 | color=alt.condition( 16 | alt.datum.nonfarm_change > 0, 17 | alt.value("steelblue"), # The positive color 18 | alt.value("orange") # The negative color 19 | ) 20 | ).properties(width=600) 21 | -------------------------------------------------------------------------------- /altair/examples/bar_chart_with_labels.py: -------------------------------------------------------------------------------- 1 | """ 2 | Bar Chart with Labels 3 | ===================== 4 | This example shows a basic horizontal bar chart with labels created with Altair. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.wheat() 11 | 12 | bars = alt.Chart(source).mark_bar().encode( 13 | x='wheat:Q', 14 | y="year:O" 15 | ) 16 | 17 | text = bars.mark_text( 18 | align='left', 19 | baseline='middle', 20 | dx=3 # Nudges text to right so it doesn't appear on top of the bar 21 | ).encode( 22 | text='wheat:Q' 23 | ) 24 | 25 | (bars + text).properties(height=900) 26 | -------------------------------------------------------------------------------- /altair/examples/interactive_brush.py: -------------------------------------------------------------------------------- 1 | """ 2 | Interactive Rectangular Brush 3 | ============================= 4 | This example shows how to add a simple rectangular brush to a scatter plot. 5 | By clicking and dragging on the plot, you can highlight points within the 6 | range. 7 | """ 8 | # category: interactive charts 9 | import altair as alt 10 | from vega_datasets import data 11 | 12 | source = data.cars() 13 | brush = alt.selection(type='interval') 14 | 15 | alt.Chart(source).mark_point().encode( 16 | x='Horsepower:Q', 17 | y='Miles_per_Gallon:Q', 18 | color=alt.condition(brush, 'Cylinders:O', alt.value('grey')) 19 | ).add_selection(brush) 20 | -------------------------------------------------------------------------------- /altair/examples/bar_chart_sorted.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sorted Bar Chart 3 | ================ 4 | This example shows a bar chart sorted by a calculated value. 5 | """ 6 | # category: bar charts 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | source = data.barley() 11 | 12 | alt.Chart(source).mark_bar().encode( 13 | x='sum(yield):Q', 14 | y=alt.Y( 15 | 'site:N', 16 | sort=alt.EncodingSortField( 17 | field="yield", # The field to use for the sort 18 | op="sum", # The operation to run on the field prior to sorting 19 | order="descending" # The order to sort in 20 | ) 21 | ) 22 | ) 23 | -------------------------------------------------------------------------------- /altair/examples/scatter_tooltips.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Scatter Plot with Tooltips 3 | --------------------------------- 4 | A scatter plot of the cars dataset, with tooltips showing selected column 5 | values when you hover over points. We make the points larger so that it is 6 | easier to hover over them. 7 | """ 8 | # category: simple charts 9 | 10 | import altair as alt 11 | from vega_datasets import data 12 | 13 | source = data.cars() 14 | 15 | alt.Chart(source).mark_circle(size=60).encode( 16 | x='Horsepower', 17 | y='Miles_per_Gallon', 18 | color='Origin', 19 | tooltip=['Name', 'Origin', 'Horsepower', 'Miles_per_Gallon'] 20 | ).interactive() 21 | -------------------------------------------------------------------------------- /altair/examples/trellis_area_sort_array.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Trellis Area Sort Chart 3 | ----------------------- 4 | This example shows small multiples of an area chart. 5 | Stock prices of four large companies 6 | sorted by `['MSFT', 'AAPL', 'IBM', 'AMZN']` 7 | ''' 8 | # category: area charts 9 | import altair as alt 10 | from vega_datasets import data 11 | 12 | source = data.stocks() 13 | 14 | alt.Chart(source).transform_filter( 15 | alt.datum.symbol != 'GOOG' 16 | ).mark_area().encode( 17 | x='date:T', 18 | y='price:Q', 19 | color='symbol:N', 20 | row=alt.Row('symbol:N', sort=['MSFT', 'AAPL', 'IBM', 'AMZN']) 21 | ).properties(height=50, width=400) 22 | -------------------------------------------------------------------------------- /altair/examples/simple_heatmap.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Heatmap 3 | -------------- 4 | This example shows a simple heatmap for showing gridded data. 5 | """ 6 | # category: simple charts 7 | import altair as alt 8 | import numpy as np 9 | import pandas as pd 10 | 11 | # Compute x^2 + y^2 across a 2D grid 12 | x, y = np.meshgrid(range(-5, 5), range(-5, 5)) 13 | z = x ** 2 + y ** 2 14 | 15 | # Convert this grid to columnar data expected by Altair 16 | source = pd.DataFrame({'x': x.ravel(), 17 | 'y': y.ravel(), 18 | 'z': z.ravel()}) 19 | 20 | alt.Chart(source).mark_rect().encode( 21 | x='x:O', 22 | y='y:O', 23 | color='z:Q' 24 | ) 25 | -------------------------------------------------------------------------------- /altair/examples/scatter_with_labels.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple Scatter Plot with Labels 3 | =============================== 4 | This example shows a basic scatter plot with labels created with Altair. 5 | """ 6 | # category: scatter plots 7 | import altair as alt 8 | import pandas as pd 9 | 10 | source = pd.DataFrame({ 11 | 'x': [1, 3, 5, 7, 9], 12 | 'y': [1, 3, 5, 7, 9], 13 | 'label': ['A', 'B', 'C', 'D', 'E'] 14 | }) 15 | 16 | bars = alt.Chart(source).mark_point().encode( 17 | x='x:Q', 18 | y='y:Q' 19 | ) 20 | 21 | text = bars.mark_text( 22 | align='left', 23 | baseline='middle', 24 | dx=7 25 | ).encode( 26 | text='label' 27 | ) 28 | 29 | bars + text 30 | -------------------------------------------------------------------------------- /altair/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .core import ( 2 | infer_vegalite_type, 3 | sanitize_dataframe, 4 | parse_shorthand, 5 | use_signature, 6 | update_subtraits, 7 | update_nested, 8 | display_traceback, 9 | SchemaBase, 10 | Undefined 11 | ) 12 | from .html import spec_to_html 13 | from .plugin_registry import PluginRegistry 14 | 15 | 16 | __all__ = ( 17 | 'infer_vegalite_type', 18 | 'sanitize_dataframe', 19 | 'spec_to_html', 20 | 'parse_shorthand', 21 | 'use_signature', 22 | 'update_subtraits', 23 | 'update_nested', 24 | 'display_traceback', 25 | 'SchemaBase', 26 | 'Undefined', 27 | 'PluginRegistry' 28 | ) 29 | -------------------------------------------------------------------------------- /altair/utils/tests/test_execeval.py: -------------------------------------------------------------------------------- 1 | from ..execeval import eval_block 2 | 3 | HAS_RETURN = """ 4 | x = 4 5 | y = 2 * x 6 | 3 * y 7 | """ 8 | 9 | NO_RETURN = """ 10 | x = 4 11 | y = 2 * x 12 | z = 3 * y 13 | """ 14 | 15 | 16 | def test_eval_block_with_return(): 17 | _globals = {} 18 | result = eval_block(HAS_RETURN, _globals) 19 | assert result == 24 20 | assert _globals['x'] == 4 21 | assert _globals['y'] == 8 22 | 23 | 24 | 25 | def test_eval_block_without_return(): 26 | _globals = {} 27 | result = eval_block(NO_RETURN, _globals) 28 | assert result is None 29 | assert _globals['x'] == 4 30 | assert _globals['y'] == 8 31 | assert _globals['z'] == 24 32 | -------------------------------------------------------------------------------- /doc/sync_website.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # get git hash for commit message 4 | GITHASH=$(git rev-parse HEAD) 5 | MSG="doc build for commit $GITHASH" 6 | cd _build 7 | 8 | # clone the repo if needed 9 | if test -d altair-viz.github.io; 10 | then echo "using existing cloned altair directory"; 11 | else git clone git@github.com:altair-viz/altair-viz.github.io.git; 12 | fi 13 | 14 | # sync the website 15 | cd altair-viz.github.io 16 | git pull 17 | 18 | # remove all tracked files 19 | git ls-files -z | xargs -0 rm -f 20 | 21 | # sync files from html build 22 | rsync -r ../html/ ./ 23 | 24 | # add commit, and push to github 25 | git add . --all 26 | git commit -m "$MSG" 27 | git push origin master 28 | -------------------------------------------------------------------------------- /altair/examples/one_dot_per_zipcode.py: -------------------------------------------------------------------------------- 1 | """ 2 | One Dot Per Zipcode 3 | ----------------------- 4 | This example shows a geographical plot with one dot per zipcode. 5 | """ 6 | # category: case studies 7 | import altair as alt 8 | from vega_datasets import data 9 | 10 | # Since the data is more than 5,000 rows we'll import it from a URL 11 | source = data.zipcodes.url 12 | 13 | alt.Chart(source).mark_circle(size=3).encode( 14 | longitude='longitude:Q', 15 | latitude='latitude:Q', 16 | color='digit:N' 17 | ).project( 18 | type='albersUsa' 19 | ).properties( 20 | width=650, 21 | height=400 22 | ).transform_calculate( 23 | "digit", alt.expr.substring(alt.datum.zip_code, 0, 1) 24 | ) 25 | -------------------------------------------------------------------------------- /altair/examples/scatter_href.py: -------------------------------------------------------------------------------- 1 | """ 2 | Scatter Plot with Href 3 | ---------------------- 4 | This example shows a scatter plot with an ``href`` encoding constructed from 5 | the car name. With this encoding, you can click on any of the points to open 6 | a google search for the car name. 7 | """ 8 | # category: scatter plots 9 | 10 | import altair as alt 11 | from vega_datasets import data 12 | 13 | source = data.cars() 14 | 15 | alt.Chart(source).transform_calculate( 16 | url='https://www.google.com/search?q=' + alt.datum.Name 17 | ).mark_point().encode( 18 | x='Horsepower:Q', 19 | y='Miles_per_Gallon:Q', 20 | color='Origin:N', 21 | href='url:N', 22 | tooltip=['Name:N', 'url:N'] 23 | ) 24 | -------------------------------------------------------------------------------- /altair/datasets.py: -------------------------------------------------------------------------------- 1 | """Datasets for use with Altair 2 | 3 | The functions here are merely thin wrappers for data access routines in the 4 | vega_datasets package. 5 | """ 6 | import warnings 7 | 8 | MSG = ("load_dataset is deprecated. " 9 | "Please use the vega_datasets package instead.") 10 | 11 | 12 | def load_dataset(name): 13 | """Load a dataset by name as a pandas.DataFrame.""" 14 | warnings.warn(MSG, DeprecationWarning) 15 | import vega_datasets 16 | return vega_datasets.data(name) 17 | 18 | 19 | def list_datasets(): 20 | """List the available datasets.""" 21 | warnings.warn(MSG, DeprecationWarning) 22 | import vega_datasets 23 | return vega_datasets.data.list_datasets() 24 | -------------------------------------------------------------------------------- /altair/examples/step_chart.py: -------------------------------------------------------------------------------- 1 | """ 2 | Step Chart 3 | ---------- 4 | This example shows Google's stock price over time. 5 | This uses the "step-after" interpolation scheme. 6 | The full list of interpolation options includes 'linear', 7 | 'linear-closed', 'step', 'step-before', 'step-after', 'basis', 8 | 'basis-open', 'basis-closed', 'cardinal', 'cardinal-open', 9 | 'cardinal-closed', 'bundle', and 'monotone'. 10 | """ 11 | # category: line charts 12 | import altair as alt 13 | from vega_datasets import data 14 | 15 | source = data.stocks() 16 | 17 | alt.Chart(source).mark_line(interpolate='step-after').encode( 18 | x='date', 19 | y='price' 20 | ).transform_filter( 21 | alt.datum.symbol == 'GOOG' 22 | ) 23 | -------------------------------------------------------------------------------- /altair/examples/scatter_matrix.py: -------------------------------------------------------------------------------- 1 | """ 2 | Scatter Matrix 3 | -------------- 4 | An example of using a RepeatChart to construct a multi-panel scatter plot 5 | with linked panning and zooming. 6 | """ 7 | # category: scatter plots 8 | import altair as alt 9 | from vega_datasets import data 10 | 11 | source = data.cars() 12 | 13 | alt.Chart(source).mark_circle().encode( 14 | alt.X(alt.repeat("column"), type='quantitative'), 15 | alt.Y(alt.repeat("row"), type='quantitative'), 16 | color='Origin:N' 17 | ).properties( 18 | width=150, 19 | height=150 20 | ).repeat( 21 | row=['Horsepower', 'Acceleration', 'Miles_per_Gallon'], 22 | column=['Miles_per_Gallon', 'Acceleration', 'Horsepower'] 23 | ).interactive() 24 | -------------------------------------------------------------------------------- /altair/examples/anscombe_plot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Anscombe's Quartet 3 | ------------------ 4 | 5 | This example shows how to use the column channel to make a trellis plot. Anscombe's Quartet is a famous dataset constructed by Francis Anscombe. Common summary statistics are identical for each subset of the data, despite the subsets having vastly different characteristics. 6 | """ 7 | # category: case studies 8 | import altair as alt 9 | from vega_datasets import data 10 | 11 | source = data.anscombe() 12 | 13 | alt.Chart(source).mark_circle().encode( 14 | alt.X('X', scale=alt.Scale(zero=False)), 15 | alt.Y('Y', scale=alt.Scale(zero=False)), 16 | column='Series' 17 | ).properties( 18 | width=150, 19 | height=150 20 | ) 21 | -------------------------------------------------------------------------------- /altair/vegalite/data.py: -------------------------------------------------------------------------------- 1 | 2 | from toolz.curried import curry, pipe 3 | from ..utils.core import sanitize_dataframe 4 | from ..utils.data import ( 5 | MaxRowsError, limit_rows, sample, to_csv, to_json, to_values, 6 | check_data_type, DataTransformerRegistry 7 | ) 8 | 9 | 10 | @curry 11 | def default_data_transformer(data, max_rows=5000): 12 | return pipe(data, limit_rows(max_rows=max_rows), to_values) 13 | 14 | 15 | __all__ = ( 16 | 'DataTransformerRegistry', 17 | 'MaxRowsError', 18 | 'curry', 19 | 'sanitize_dataframe', 20 | 'default_data_transformer', 21 | 'limit_rows', 22 | 'pipe', 23 | 'sample', 24 | 'to_csv', 25 | 'to_json', 26 | 'to_values', 27 | 'check_data_type' 28 | ) 29 | -------------------------------------------------------------------------------- /doc/_static/theme_overrides.css: -------------------------------------------------------------------------------- 1 | /* override table width restrictions */ 2 | @media screen and (min-width: 767px) { 3 | 4 | .wy-table-responsive table td { 5 | /* !important prevents the common CSS stylesheets from overriding 6 | this as on RTD they are loaded after this stylesheet */ 7 | white-space: normal !important; 8 | } 9 | .wy-table-responsive { 10 | overflow: visible !important; 11 | } 12 | } 13 | 14 | .rst-content dl:not(.docutils) dt em { 15 | font-style: normal !important; 16 | line-height: 1.4em !important; 17 | } 18 | 19 | .rst-content div[class^='highlight'] { 20 | background: #fff !important; 21 | } 22 | 23 | img.logo { 24 | width: 120px !important; 25 | } 26 | -------------------------------------------------------------------------------- /altair/examples/gapminder_bubble_plot.py: -------------------------------------------------------------------------------- 1 | """ 2 | Gapminder Bubble Plot 3 | ===================== 4 | This example shows how to make a bubble plot showing the correlation between 5 | health and income for 187 countries in the world (modified from an example 6 | in Lisa Charlotte Rost's blog post `'One Chart, Twelve Charting Libraries'