import altair as alt
from vega_datasets import data
= alt.topo_feature(data.londonBoroughs.url, 'boroughs')
boroughs = alt.topo_feature(data.londonTubeLines.url, 'line')
tubelines = data.londonCentroids.url centroids
= alt.Chart(boroughs, width=700, height=500).mark_geoshape(
background ='white',
stroke=2
strokeWidth
).encode(=alt.value('#eee'),
color
)= alt.Chart(centroids).mark_text().encode(
labels ='cx:Q',
longitude='cy:Q',
latitude='bLabel:N',
text=alt.value(8),
size=alt.value(0.6)
opacity
).transform_calculate("bLabel", "indexof (datum.name,' ') > 0 ? substring(datum.name,0,indexof(datum.name, ' ')) : datum.name"
)
= alt.Scale(domain=["Bakerloo", "Central", "Circle", "District", "DLR",
line_scale "Hammersmith & City", "Jubilee", "Metropolitan", "Northern",
"Piccadilly", "Victoria", "Waterloo & City"],
range=["rgb(137,78,36)", "rgb(220,36,30)", "rgb(255,206,0)",
"rgb(1,114,41)", "rgb(0,175,173)", "rgb(215,153,175)",
"rgb(106,114,120)", "rgb(114,17,84)", "rgb(0,0,0)",
"rgb(0,24,168)", "rgb(0,160,226)", "rgb(106,187,170)"])
= alt.Chart(tubelines).mark_geoshape(
lines =False,
filled=2
strokeWidth
).encode('id:N')
alt.Color(None)
.title(='bottom-right', offset=0)
.legend(orient
.scale(line_scale)
)
+ labels + lines background
import altair as alt
from vega_datasets import data
import geopandas as gpd
= "https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip"
url = gpd.read_file(url) # zipped shapefile
gdf_ne = gdf_ne[["NAME", "CONTINENT", "POP_EST", 'geometry']]
gdf_ne
alt.Chart(gdf_ne).mark_geoshape(='lightgrey',stroke='white',strokeWidth=0.5
fill )
Geo Pandas
import geopandas
from geodatasets import get_path
= get_path("nybb")
path_to_data = geopandas.read_file(path_to_data) gdf
import matplotlib.pyplot as plt
%config InlineBackend.figure_format='retina'
=plt.gca()
ax=ax)
gdf.plot(ax=ax,color='white') gdf.centroid.plot(ax
gdf.explore()
Make this Notebook Trusted to load map: File -> Trust Notebook