-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot.py
106 lines (87 loc) · 2.9 KB
/
plot.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
PLOTLY_API_KEY = "wYBVjzEQ7vTR5vNPSvq7"
import matplotlib.pyplot as plt
import plotly.graph_objs as go
import plotly
from plotly.graph_objs import Data, Scattermapbox, Marker, Layout, Line
import plotly.plotly as py
import pandas as pd
import colorlover
# UTILS
def config_plotly():
plotly.tools.set_config_file(world_readable=True,
sharing='public')
plotly.tools.set_credentials_file(username='rkucharski',
api_key=PLOTLY_API_KEY)
# PLOTS
def plot_vectors(days, peak="PM"):
_scaler = 6
config_plotly()
color_scale = colorlover.scales['5']['qual']['Dark2']
data = list()
top_size = days['7'].max()
for index, row in days.iterrows():
desc = str(index) + " cluster_id" + str(row['cluster_id'])
data.append(Scattermapbox(
lat=[row["Start_Lat_mean" + peak], row["End_Lat_mean" + peak]],
lon=[row["Start_Lon_mean" + peak], row["End_Lon_mean" + peak]],
mode='lines',
text=desc,
name=desc,
opacity = 0.7,
line=Line(width=int(_scaler * row['7']/top_size),
color=color_scale[int(row['cluster_id'])])))
data = Data(data)
layout = Layout(
showlegend=False,
autosize=True,
hovermode='closest',
mapbox=dict(
accesstoken=PLOTLY_API_KEY,
bearing=0,
center=dict(
lat=row["Start_Lat_mean" + peak],
lon=row["Start_Lon_mean" + peak]
),
pitch=0,
zoom=11
),
)
fig = dict(data=data, layout=layout)
py.plot(fig, filename='Vectors ' + peak)
def plot_cluster(days, param="End", peak="AM", marker_size_scale=30):
config_plotly()
color_scale = colorlover.scales['5']['qual']['Set1']
data = list()
top_size = days['7'].max()
for cluster in days.cluster_id.unique():
data.append(Scattermapbox(
lat=days[days.cluster_id == cluster][param + "_Lat_mean" + peak],
lon=days[days.cluster_id == cluster][param + "_Lon_mean" + peak],
mode='markers',
marker=Marker(
size=days[days.cluster_id == cluster]['7'] / top_size * marker_size_scale,
color=color_scale[cluster]
),
text="CL: "+str(cluster),
hoverinfo='text'
))
data = Data(data)
layout = Layout(
title='Clusters centres of gravity:' + param + peak,
autosize=True,
hovermode='closest',
showlegend=False,
mapbox=dict(
accesstoken=PLOTLY_API_KEY,
bearing=0,
center=dict(
lat=40,
lon=-73
),
pitch=0,
zoom=7,
style='light'
),
)
fig = dict(data=data, layout=layout)
py.plot(fig, filename='Clusters:' + param + peak)