Space-time visualisations (giddy)

from pysal.lib.weights.contiguity import Queen
from pysal.lib import examples
import geopandas as gpd
import pandas as pd
import numpy as np
from pysal.explore.giddy.directional import Rose
import matplotlib.pyplot as plt
from pysal.explore import esda
from pysal.viz.splot.esda import lisa_cluster

from ipywidgets import interact, fixed
import ipywidgets as widgets

%matplotlib inline
plt.style.use('ggplot')

Data prepration

# get csv and shp and merge
shp_link = examples.get_path('us48.shp')
df = gpd.read_file(shp_link)
income_table = pd.read_csv(examples.get_path("usjoin.csv"))

# calculate relative values
for year in range(1969, 2010):
    income_table[str(year) + '_rel'] = income_table[str(year)] / income_table[str(year)].mean()

# merge
gdf = df.merge(income_table,left_on='STATE_NAME',right_on='Name')

#retrieve spatial weights and data for two points in time
w = Queen.from_dataframe(gdf)
w.transform = 'r'
y1 = gdf['1969_rel'].values
y2 = gdf['2000_rel'].values

# create rose object
Y = np.array([y1, y2]).T
rose = Rose(Y, w, k=5)

# calculate Moran_Local
moran_loc1 = esda.moran.Moran_Local(y1, w)
moran_loc2 = esda.moran.Moran_Local(y2, w)

Plotting

from pysal.viz.splot.giddy import (dynamic_lisa_heatmap,
                         dynamic_lisa_rose,
                         dynamic_lisa_vectors,
                         dynamic_lisa_composite,
                         dynamic_lisa_composite_explore)
from pysal.viz import splot

fig, ax = dynamic_lisa_heatmap(rose)
ax.set_ylabel(1996)
ax.set_xlabel(2006)
plt.show()

png

fig, ax = dynamic_lisa_rose(rose, attribute=y1)
plt.show()

png

fig, ax = dynamic_lisa_vectors(rose)

png

dynamic_lisa_composite(rose, gdf)
plt.show()

png

dynamic_lisa_composite_explore(rose, gdf, pattern='rel')
plt.show()

interactive(children=(Dropdown(description='start_time', options={'1969_rel': '1969_rel', '1970_rel': '1970_re…