GeoViews is a Python library that makes it easy to explore and visualize geographical
GeoViews is built on the HoloViews library for building flexible visualizations of multidimensional data
You can install GeoViews and its dependencies using conda:
import geoviews as gv
import geoviews.feature as gf
import xarray as xr
from cartopy import crs
gv.extension('bokeh', 'matplotlib')
We can visualize the global as following
gf.ocean
and we can improve it as follows
gf.ocean.options(
'Feature', projection=crs.Geostationary(), global_extent=True, height=525,width=525,
)
We can show the lands only too
gf.land.options(
'Feature', projection=crs.Geostationary(), global_extent=True, height=525,width=525,
)
with the borders
(gf.ocean * gf.land * gf.coastline * gf.borders).options(
'Feature', projection=crs.Geostationary(), global_extent=True, height=525,width=525,
)
We will consider first some datasets already uploaded in geoviews Library
import geopandas as gpd
d1=gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
d1.head(n=10)
World population Map
gv.Polygons(d1, vdims=[('pop_est','Population'), ('name', 'Country')]).options(
tools=['hover'], width=800, height=500, projection=crs.Robinson()
)
Saving the map into an html file
g1=gv.Polygons(d1, vdims=[('pop_est','Population'), ('name', 'Country')]).options(
tools=['hover'], width=800, height=500, projection=crs.Robinson()
)
renderer = gv.renderer('bokeh')
renderer.save(g1, 'population')
import pandas as pd
import geoviews as gv
gv.extension('bokeh')
cities = pd.read_csv('cities.csv', encoding="ISO-8859-1")
population = gv.Dataset(cities, kdims=['City', 'Country', 'Year'])
population.columns
points = population.to(gv.Points, ['Longitude', 'Latitude'], ['Population', 'City', 'Country'])
tiles = gv.tile_sources.StamenWatercolor
%%opts Points (size=0.003 cmap='viridis') [tools=['hover'] size_index=2 color_index=2 width=600]
tiles * points
%%opts Points (size=0.003 cmap='viridis') [tools=['hover'] size_index=2 color_index=2 width=800 height=600 xaxis=None yaxis=None toolbar=None]
g2=tiles * points
renderer = gv.renderer('bokeh')
renderer.save(g2, 'population2')
g2
Loading Libraries
import pandas as pd
import geoviews as gv
gv.extension('bokeh')
Importing the data: The data that I will be using here is available here
df = pd.read_csv('gdp_gps_years.csv', encoding="ISO-8859-1")
df.columns
gdp = gv.Dataset(df, kdims=['Country', 'Year'])
gdp.columns
points = gdp.to(gv.Points, ['Longitude', 'Latitude'], ['GDP(current$)', 'Country'])
tiles = gv.tile_sources.StamenWatercolor
%%opts Points (size=0.000015 cmap='viridis') [tools=['hover'] size_index=2 color_index=2 width=800 height=600 xaxis=None yaxis=None toolbar=None]
tiles * points
renderer = gv.renderer('bokeh')
gdp1=tiles * points
renderer.save(gdp1, 'gdp1')