Space-time visualisations (giddy)


In [1]:
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


In [2]:
# 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"))

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

In [4]:
# merge
gdf = df.merge(income_table,left_on='STATE_NAME',right_on='Name')

In [5]:
#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

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

In [7]:
# calculate Moran_Local
moran_loc1 = esda.moran.Moran_Local(y1, w)
moran_loc2 = esda.moran.Moran_Local(y2, w)

Plotting


In [8]:
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

In [9]:
fig, ax = dynamic_lisa_heatmap(rose)
ax.set_ylabel(1996)
ax.set_xlabel(2006)
plt.show()



In [10]:
fig, ax = dynamic_lisa_rose(rose, attribute=y1)
plt.show()



In [11]:
fig, ax = dynamic_lisa_vectors(rose)



In [12]:
dynamic_lisa_composite(rose, gdf)
plt.show()



In [13]:
dynamic_lisa_composite_explore(rose, gdf, pattern='rel')
plt.show()