我正在尝试在Altair中重新创建类似于this vega plot的内容。
在绑定到mark_geoshape
之类的东西color
之前,我曾经很幸运地构建过encode
映射,但是我一生都无法弄清楚将滑块绑定到图表的rotate
属性,该属性位于project
中。
我想我可以做这样的事情,但是没有运气:
import altair as alt
from vega_datasets import data
# Data generators for the background
sphere = alt.sphere()
graticule = alt.graticule()
# Source of land data
source = alt.topo_feature(data.world_110m.url, 'countries')
slider = alt.binding_range(min=0, max=100, step=1, name='rotate:')
selector = alt.selection_single(name="SelectorName", fields=['rotate'],
bind=slider, init={'rotate': 180})
# Layering and configuring the components
alt.layer(
alt.Chart(sphere).mark_geoshape(),
alt.Chart(graticule).mark_geoshape(stroke='white', strokeWidth=0.5),
alt.Chart(source).mark_geoshape(fill='ForestGreen', stroke='black')
).project(
'orthographic',
).encode(
rotate=['rotate',180,180]
).properties(width=600, height=400, selection=selector).configure_view(stroke=None)
任何帮助将不胜感激。
谢谢 狮子座
答案 0 :(得分:1)
Altair中目前无法做到这一点:Vega-Lite模式仅支持恒定旋转值。如果愿意,可以在Vega中进行; https://vega.github.io/vega/docs/projections/有一个例子。