-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is it possible to set the extent and zoom with a mark_geoshape? #632
Comments
No, this is not supported at the moment. See vega/vega-lite#3305 |
I found a workaround, and wrote a small post about it here. I'll just paste the contents here, in case the link dies later. "Zooming in" on a map in AltairAltair doesn't allow making maps (aka I stumbled upon this problem when I needed to only display information in only one US state, but the official example shows the full map of the US. Furthermore, it's not possible to set a fixed zoom, so that only one state is visible when the map is shown. I found a solution by essentially only displaying the state I need, instead of the whole map. For that, I had to find the relevant geometry file. I found a GeoJson file for the state I was interested in from world.geo.json repo (state files are located here, below the folders). Then, I loaded it into Geojson.io geojson.io, and exported as TopoJson (I'm sure it could be done via better means, but this was the quickest). Finally, I simply used the local file in my notebook as such: state = alt.topo_feature('./map.topojson', 'collection')
(
alt.Chart(state)
.mark_geoshape(
fill='white',
stroke='black'
)
.project(type='albersUsa')
) Note that the second argument to {
"type": "Topology",
"objects": {
"collection": { <--------- this is the argument
"type": "GeometryCollection",
"geometries": [
{
"type": "Polygon",
"id": "USA-TX",
"properties": {
"fips": 48,
"name": "Texas"
},
... Hope this helps while vega-lite gets the required functionality! |
Say, for instance, I wanted to zoom in on Los Angeles County on map of U.S. states example included in the documentation.
Could I set the "scale" or otherwise change the extent so that LA, or any other location, was at the center of the map?
The text was updated successfully, but these errors were encountered: