Yet Another Geographer

Mpl Is Just Fine

I’ve been using matplotlib for nearly 5 years at least once a week. I’m still learning things that exist within the pylab interface… not the most ideal UX. For instance, I just learned about plt.axvline, which I could use to draw vertical lines in my code instead of what I usually use, plt.vlines(coordinate_list, *plt.gca().get_ylim()), but it’s not as general as plt.vlines since it actually plots a rectangle. Still, though, for most of what I do (which is a single vertical line for drawing specific axes/time breaks in a plot) it’s easier.

Annoscatter

I found this function super useful in my dissertation and more generally in my work. What it does is take x,y coordinates and a set of strings and annotates a scatterplot using those labels. For example, here’s a figure from my dissertation where I use it to annotate a plot of regression leverage by year. I jitter the points a little to provide legibility to the text labels, but basically it’s just a call like annoscatter(df.

Spatial Autocorrelation Functions

I looked into using spatial autocorrelation functions in my dissertation to characterize the ``scale'' at which processes operate electorally. I did an analysis of presidential vote by county, trying to identify where, exactly, clusters of votes tend to become decorrelated. The typical diameter at which the so-called “spatial autocorrelation function” goes to zero denotes how wide a typical spatial cluster might be, and the partial spatial autocorrelation function gives an anticipated order at which spatial autocorrelation may hold.

throwing in a spatially-correlated random effect may mess up the fixed effect you love - revisiting Hodges and Reich (2010) for SAR models

import pysal as ps import numpy as np import pandas as pd import matplotlib.pyplot as plt import geopandas as gpd %matplotlib inline This is just a quick demonstration of what I understand from Hodges & Reich (2010)’s argument about the structure of spatial error terms. Essentially, his claim is that the substantive estimates ($\hat{\beta}$) from an ordinary least squares regression over $N$ observations and $P$ covariates: $$ Y \sim \mathcal{N}(X\hat{\beta}, \sigma^2)$$

Does projection matter for compactness indices?

This is a quick and dirty exploration of the compactness impacts of changing the projection of data on compactness measures. import geopandas as gpd import numpy as np import matplotlib.pyplot as plt from compact import reock as _reock import pysal as ps import seaborn as sns %matplotlib inline The data I’m using is the 113th districts from my Scientific Data publication, sourced originally from Jeff Lewis. df = gpd.read_file('./districts113.shp').query('STATENAME not in ("Alaska","Hawaii")') df.