import geopandas as gpd
from lets_plot import *
LetsPlot.setup_html()
from lets_plot import *
from lets_plot.geo_data import *
# %%
offices = [
["Prague", "CZ", "Headquarters", 100],
["Petersburg", "Russia", "R&D Center", 1000],
["Moscow", "Russia", "R&D Center", 100],
["Novosibirsk", "Russia", "R&D Center", 50],
["München", "Germany", "R&D Center", 200],
["Amsterdam", "Netherlands", "R&D Center", 100],
["Boston", "US", "R&D Center", 10],
["Marlton", "US", "Sales", 10],
["Foster City", "US", "Sales", 10],
]
dat = dict(
city=[o[0] for o in offices],
country=[o[1] for o in offices],
kind=[o[2] for o in offices],
size=[o[3] for o in offices],
)
# %%
# Geocoding
city_geocoder = geocode_cities(dat['city']).countries(dat['country'])
# %%
# The map of JetBrains major offices worldwide.
p = (ggplot(dat) +
# geom_livemap() +
geom_point(
# aes(color='kind', shape='kind', size='size'),
aes(color='kind'),
size=10,
map_join = [['city'], ['city']],
#map=city_geocoder))
map=city_geocoder.get_centroids()))
p.show()
gpd.datasets.available
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
print(world.size)
world[100:120]
ggplot() + geom_polygon(aes(fill='continent'), data=world) + ggsize(800, 400)
ggplot() + geom_path(data=world)
ggplot() + geom_map(data=world)
ggplot() + geom_polygon(map=world)
ggplot() + geom_map(map=world)
ggplot() + geom_point(map=world)
ggplot() + geom_rect(map=world, alpha=.3)
cities = gpd.read_file(gpd.datasets.get_path('naturalearth_cities'))
cities
ggplot() + geom_point(data=cities)
ggplot() + geom_point(map=cities)
import random
cityNames = cities['name'].tolist()
cityValue = [random.randint(10, 100) for _ in cityNames]
cityData = dict(city=cityNames, val=cityValue)
ggplot() + geom_point(aes(color='val'), data=cityData, map=cities, map_join=('city', 'name'), size=7)
citiesWithKey = cities.rename(columns = {'name':'key'}, inplace = False)
citiesWithKey
ggplot() + geom_point(aes(color='val'), data=cityData, map=citiesWithKey, map_join=('city', 'key'), size=7)
ggplot() + ggsize(800, 400)\
+ geom_polygon(aes(fill='continent'), data=world)\
+ geom_point(data=cities, color='cyan')
ggplot() + ggsize(800, 400)\
+ geom_rect(aes(fill='continent'), data=world)\
+ geom_point(data=cities, color='cyan', size=7, alpha=.5)
nybb = gpd.read_file(gpd.datasets.get_path('nybb'))
print(nybb.size)
nybb.head()
ggplot() + geom_polygon(aes(fill='BoroName'), data=nybb)
ggplot() + geom_polygon(aes(fill='BoroName'), data=nybb) + coord_cartesian(xlim=[-74.05,-73.95],ylim=[40.675,40.725])