世界地图投影#
此示例显示了世界各国的地图。使用下拉菜单比较地图投影。有关 project 参数的更多详细信息,请参阅 altair.Projection 的 API。
import altair as alt
from vega_datasets import data
source = alt.topo_feature(data.world_110m.url, 'countries')
input_dropdown = alt.binding_select(options=[
"albers",
"albersUsa",
"azimuthalEqualArea",
"azimuthalEquidistant",
"conicEqualArea",
"conicEquidistant",
"equalEarth",
"equirectangular",
"gnomonic",
"mercator",
"naturalEarth1",
"orthographic",
"stereographic",
"transverseMercator"
], name='Projection ')
param_projection = alt.param(value="equalEarth", bind=input_dropdown)
alt.Chart(source, width=500, height=300).mark_geoshape(
fill='lightgray',
stroke='gray'
).project(
type=alt.expr(param_projection.name)
).add_params(param_projection)
import altair as alt
from vega_datasets import data
source = alt.topo_feature(data.world_110m.url, 'countries')
input_dropdown = alt.binding_select(options=[
"albers",
"albersUsa",
"azimuthalEqualArea",
"azimuthalEquidistant",
"conicEqualArea",
"conicEquidistant",
"equalEarth",
"equirectangular",
"gnomonic",
"mercator",
"naturalEarth1",
"orthographic",
"stereographic",
"transverseMercator"
], name='Projection ')
param_projection = alt.param(value="equalEarth", bind=input_dropdown)
alt.Chart(source, width=500, height=300).mark_geoshape(
fill='lightgray',
stroke='gray'
).project(
type=alt.expr(param_projection.name)
).add_params(param_projection)
# No channel encoding options are specified in this chart
# so the code is the same as for the method-based syntax.