Open
Description
When using Altair for plotting geographic objects, the visualization automatically chooses an appropriate projection.
However if we overlay another object, I would like to rescale / crop the chart to have a better zoomed view
Example:
import altair as alt
# inspired by: https://altair-viz.github.io/gallery/london_tube.html
london_boroughs_url = 'https://raw.githubusercontent.com/vega/vega-datasets/next/data/londonBoroughs.json'
boroughs_centroids_url = 'https://raw.githubusercontent.com/vega/vega-datasets/next/data/londonCentroids.json'
boroughs = alt.topo_feature(london_boroughs_url, 'boroughs')
background = alt.Chart(boroughs).mark_geoshape(
stroke='white',
strokeWidth=2
).encode(
color=alt.value('#eee'),
)
labels = alt.Chart(boroughs_centroids_url).mark_text().encode(
longitude='cx:Q',
latitude='cy:Q',
text='bLabel:N',
size=alt.value(8),
opacity=alt.value(0.6)
).transform_calculate(
"bLabel", "indexof (datum.name,' ') > 0 ? substring(datum.name,0,indexof(datum.name, ' ')) : datum.name"
)
london = background + labels
print(london.projection) # undefined !!
display(london)
The above display returns the following image:
Where an appropriate projection has been chosen. If I add an additional object on the chart.
# source = ....
points = alt.Chart(source).mark_line().encode(
longitude='longitude_degs:Q',
latitude='latitude_degs:Q', order='index')
chart = london + points
display(chart)
The projection chosen is based on the largest fitting projection. However I would like to "zoom" in on the smaller object
Something along the lines of:
chart = (london + points).project(points.projection)
But of course, points.projection
is also undefined.
Please follow these steps to make it more efficient to respond to your feature request.
- Since Altair is a Python wrapper around the Vega-Lite visualization grammar, most feature requests should be reported directly to Vega-Lite. You can click the Action Button of your Altair chart and "Open in Vega Editor" to create a reproducible Vega-Lite example.
- Search for duplicate issues.
- Describe the feature's goal, motivating use cases, and its expected behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment