Skip to content

Instantly share code, notes, and snippets.

@linwoodc3
Last active April 22, 2017 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save linwoodc3/cd5fd542a6aaa1940aac09efd38748cb to your computer and use it in GitHub Desktop.
Save linwoodc3/cd5fd542a6aaa1940aac09efd38748cb to your computer and use it in GitHub Desktop.
Simple code to create a choropleth based on the number of tweets.
def continentlabs(row):
shape = row['geometry'].centroid
x,y = shape.x,shape.y
return (x,y,row['name'])
%matplotlib inline
from matplotlib import legend
f, ax = plt.subplots(1, figsize=(20, 12))
gpd.read_file(gpd.datasets.get_path('naturalearth_lowres')).plot(ax=ax,color='white',linewidth=0.2)
gdf.merge(countdf,left_on='name',right_on='NAME').plot(column='counted',cmap='OrRd',scheme='Fisher_Jenks',ax=ax,linewidth=0.1,edgecolor='white',legend=True,alpha=0.4)
ax.set_facecolor('#1C6BA0')
labels = shapefilereader('../data/ne_110m_geography_regions_polys.zip') # http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_geography_regions_polys.zip
b = labels.drop_duplicates(['name'],keep='last').drop_duplicates('region').apply(continentlabs,axis=1)
for l in b.values:
ax.text(l[0],l[1],l[2],fontsize=25)
ax.grid(False)
plt.title("Measure of Twitter Usage by Country",fontsize=25)
leg = ax.get_legend()
leg.set_bbox_to_anchor((0., 0.31, 0.4, 0.4))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment