Skip to content

Commit

Permalink
Merge pull request #1714 from mattijn/type-geojson
Browse files Browse the repository at this point in the history
ENH: add datatype geojson
  • Loading branch information
jakevdp authored Oct 1, 2019
2 parents 2831753 + 22d0d04 commit a8633e4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
30 changes: 30 additions & 0 deletions altair/examples/us_incomebrackets_by_state_facet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
US Income by State: Wrapped Facet
---------------------------------
This example shows how to create a map of income in the US by state,
faceted over income brackets
"""
# category: maps

import altair as alt
from vega_datasets import data

states = alt.topo_feature(data.us_10m.url, 'states')
source = data.income.url

alt.Chart(source).mark_geoshape().encode(
shape='geo:G',
color='pct:Q',
tooltip=['name:N', 'pct:Q'],
facet='group:N'
).transform_lookup(
lookup='id',
from_=alt.LookupData(data=states, key='id'),
as_='geo'
).properties(
width=300,
height=175,
columns=2
).project(
type='albersUsa'
)
3 changes: 2 additions & 1 deletion altair/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ def infer_dtype(value):
TYPECODE_MAP = {'ordinal': 'O',
'nominal': 'N',
'quantitative': 'Q',
'temporal': 'T'}
'temporal': 'T',
'geojson': 'G'}

INV_TYPECODE_MAP = {v: k for k, v in TYPECODE_MAP.items()}

Expand Down
2 changes: 2 additions & 0 deletions altair/utils/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ def check(s, **kwargs):
check('foobar:nominal', type='nominal', field='foobar')
check('foobar:ordinal', type='ordinal', field='foobar')
check('foobar:temporal', type='temporal', field='foobar')
check('foobar:geojson', type='geojson', field='foobar')

check('foobar:Q', type='quantitative', field='foobar')
check('foobar:N', type='nominal', field='foobar')
check('foobar:O', type='ordinal', field='foobar')
check('foobar:T', type='temporal', field='foobar')
check('foobar:G', type='geojson', field='foobar')

# Fields with aggregate and/or type
check('average(foobar)', field='foobar', aggregate='average')
Expand Down
1 change: 0 additions & 1 deletion altair/vegalite/v3/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,6 @@ def test_filter_transform_selection_predicates():
assert chart.to_dict()['transform'] == [{'filter': {'selection': {'or': ['s1', 's2']}}}]



def test_resolve_methods():
chart = alt.LayerChart().resolve_axis(x='shared', y='independent')
assert chart.resolve == alt.Resolve(axis=alt.AxisResolveMap(x='shared', y='independent'))
Expand Down
1 change: 1 addition & 0 deletions doc/user_guide/encoding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ quantitative ``Q`` a continuous real-valued quantity
ordinal ``O`` a discrete ordered quantity
nominal ``N`` a discrete unordered category
temporal ``T`` a time or date value
geojson ``G`` a geographic shape
============ ============== ================================================

If types are not specified for data input as a DataFrame, Altair defaults to
Expand Down

0 comments on commit a8633e4

Please sign in to comment.