/
plotting_functions.py
69 lines (55 loc) · 2.04 KB
/
plotting_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 11 20:42:36 2015
@author: Aaron Foss
"""
def plot_update_frequency(result):
import pandas as pd
import numpy
#turns query results into timeseries of chnages
d = []
v = []
for res in result:
d.append(pd.Timestamp(res['_id']['timestamp']).to_datetime())
v.append(res['count'])
ts = pd.DataFrame(v, index = d, columns = ['changes'])
ts = ts.resample('W', how='sum')
ts.index.names = ['date']
import ggplot
#plots timeseries of changes
p = ggplot.ggplot(ts, ggplot.aes(x = ts.index, y=ts['changes'])) +\
ggplot.geom_point(color = 'blue') +\
ggplot.xlab('Period') +\
ggplot.ylab('Changes') +\
ggplot.geom_smooth() +\
ggplot.ylim(low = 0) +\
ggplot.scale_x_date(breaks = ggplot.date_breaks("12 months"), labels = ggplot.date_format('%Y-%m')) +\
ggplot.ggtitle('OpenStreetMaps Denver-Boulder\nChanges per Week')
return p
def plot_locations(result,amenity,top):
import pandas as pd
import numpy
lat = []
lon = []
for res in result:
lat.append(res['pos'][0])
lon.append(res['pos'][1])
geo = pd.DataFrame(lat, columns = ['lat'])
geo['lon'] = lon
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
my_map = Basemap(projection='merc', lat_0=geo.median()[0], lon_0=geo.median()[1],
resolution = 'h', area_thresh = .1,
llcrnrlon=geo.min()[1]-.1, llcrnrlat=geo.min()[0]-.1,
urcrnrlon=geo.max()[1]+.1, urcrnrlat=geo.max()[0]+.1)
my_map.drawrivers()
my_map.drawcounties()
my_map.fillcontinents(color='tan')
my_map.drawmapboundary()
my_map.drawcoastlines()
x,y = my_map(lon, lat)
my_map.plot(x,y, 'bo', markersize=2)
title = 'Map Showing %s Added by \"%s\"\nThe Top %s Editor' % (str(amenity).title(),str(top),str(amenity).title())
plt.title(title)
p = plt.show()
return p