%matplotlib inline
import warnings
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import pandas as pd
import sqlalchemy as sa
ENGINE = sa.create_engine('postgresql://postgres@/glottolog3')
QUERY = '''
SELECT id AS glottocode, latitude, longitude
FROM language JOIN languoid USING (pk)
WHERE level = 'language'
ORDER BY id
'''.strip()
df = pd.read_sql_query(QUERY, ENGINE, index_col='glottocode')
df.info(memory_usage='deep')
assert df.index.is_unique
assert df.index.is_monotonic_increasing
df.head()
<class 'pandas.core.frame.DataFrame'> Index: 8549 entries, aari1239 to zyph1238 Data columns (total 2 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 latitude 8226 non-null float64 1 longitude 8226 non-null float64 dtypes: float64(2) memory usage: 676.2 KB
latitude | longitude | |
---|---|---|
glottocode | ||
aari1239 | 5.95034 | 36.5721 |
aari1240 | NaN | NaN |
aasa1238 | -4.00679 | 36.8648 |
abad1241 | -9.03389 | 146.9920 |
abag1245 | -6.12028 | 145.6650 |
fig, ax = plt.subplots(figsize=(12, 6))
ax.axis([-180, 180, -90, 90])
ax.set_xticks(range(-180, 181, 90))
ax.set_yticks(range(-90, 91, 45))
ax.scatter('longitude', 'latitude', 1, color='k', data=df);
def shifted(degrees=180):
"""Return a function shifting longitudes westward by given degrees."""
degrees %= 360
cutoff = degrees - 180
def shift(x):
return x - degrees if x > cutoff else 360 + x - degrees
return shift
fig, ax = plt.subplots(figsize=(12, 6))
ax.axis([-180, 180, -90, 90])
ax.set_xticks(range(-180 + 25, 180 + 25, 90))
ax.set_xticklabels([0, 90, 180, -90])
ax.set_yticks(range(-90, 91, 45))
ax.scatter('longitude', 'latitude', 1, color='k',
data=df.assign(longitude=df['longitude'].map(shifted(155))));
warnings.simplefilter('ignore')
fig, ax = plt.subplots(figsize=(12, 6))
m = Basemap(ax=ax, projection='cyl', lon_0=155)
m.drawparallels(range(-90, 91, 30), dashes=[], linewidth=.25, labels=[1, 0, 0, 0])
m.drawmeridians(range(0, 360, 60), dashes=[], linewidth=.25, labels=[0, 0, 0, 1])
m.scatter(df['longitude'].values, df['latitude'].values, 1, color='k', latlon=True);
fig, ax = plt.subplots(figsize=(12, 6))
m = Basemap(ax=ax, projection='robin', lon_0=155)
m.drawparallels(range(-90, 91, 30), dashes=[], linewidth=.25, labels=[1, 0, 0, 0])
m.drawmeridians(range(0, 360, 60), dashes=[], linewidth=.25, labels=[0, 0, 0, 1])
m.scatter(df['longitude'].values, df['latitude'].values, 1, color='k', latlon=True);
fig, ax = plt.subplots(figsize=(12, 6))
m = Basemap(ax=ax, projection='eck4', lon_0=155)
m.drawparallels(range(-90, 91, 30), dashes=[], linewidth=.25, labels=[1, 0, 0, 0])
m.drawmeridians(range(0, 360, 60), dashes=[], linewidth=.25, labels=[0, 0, 0, 1])
m.scatter(df['longitude'].values, df['latitude'].values, 1, color='k', latlon=True);