【发布时间】:2022-01-07 16:34:49
【问题描述】:
我需要从this website 绘制爱达荷州的河流
当我将它加载到 geopandas 并尝试通过 altair.Chart().mark_geoshape() 绘制它时,我的图表出现了一堆随机线,它们没有按预期绘制。我不知道发生了什么,因为我是地理空间数据方面的新手。
我遵循此示例中的模式https://altair-viz.github.io/gallery/london_tube.html,但无法绘制线条。
任何想法或我如何做到这一点都会有很大帮助!下面是我正在使用的代码。谢谢!
import altair as alt
import geopandas as gpd
from vega_datasets import data
states = alt.topo_feature(data.us_10m.url,'states')
hydro = gpd.read_file('drive/MyDrive/data_cse350/hyd250/hyd250.shp')
rivers = hydro.loc[hydro.FEAT_NAME.isin(['Snake River','Henrys Fork'])]
rchart = alt.Chart(rivers).mark_geoshape().encode(color = 'FEAT_NAME')
idaho = alt.Chart(states).mark_geoshape(fill = 'white',stroke = 'black').project(
'albersUsa'
).transform_calculate(state_id = "(datum.id)"
).transform_filter((alt.datum.state_id)==16)
rchart+idaho```
If you can solve this, that would be great! Thank you for your help! I have already spent waaaayyy too many hours on getting this to work.
【问题讨论】:
-
我不习惯在 Altair 中使用地图,但您给出的示例是带有 topojson 线路信息的 topojson 底图。您可能需要使用相同的数据格式。