-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotting.py
More file actions
44 lines (35 loc) · 1.39 KB
/
plotting.py
File metadata and controls
44 lines (35 loc) · 1.39 KB
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
from decouple import config
import plotly.express as px
import chart_studio
from chart_studio import plotly as py
# Setting credentials
px.set_mapbox_access_token(config('mapbox_public_token'))
cs_username = config('chart_studio_username')
cs_api = config('chart_studio_api')
chart_studio.tools.set_credentials_file(username=cs_username,
api_key=cs_api)
class SpatialMapping:
def plot_map(self, dataframe):
fig = px.scatter_mapbox(
dataframe, lat="latitude", lon="longitude",
color="counts",
size="counts",
color_continuous_scale=px.colors.sequential.Greens,
size_max=20,
zoom=1,
hover_data=["country", 'counts'],
hover_name='country')
fig.update_layout(
title='WhatsApp Analytics: Spatial Mapping of WhatsApp group contacts',
mapbox_style="dark")
fig.show()
print('The link to the plot can be found here: ', py.plot(
fig, filename='Whatsapp Analytics Map', auto_open=True))
def plot_bar(self, dataframe):
fig = px.bar(
dataframe, x='country', y='counts',
hover_data=["country", 'counts'],
color_discrete_sequence=['darkgreen'])
fig.update_layout(
title='WhatsApp Analytics: Distribution of WhatsApp group contacts')
fig.show()