Plotly maps added
This commit is contained in:
parent
b68790bc00
commit
9c911610eb
3 changed files with 57 additions and 5 deletions
51
geofp.py
51
geofp.py
|
|
@ -13,6 +13,7 @@ import sys
|
|||
import numpy as np
|
||||
import pandas as pd
|
||||
import pygal
|
||||
import plotly.plotly as py
|
||||
import json
|
||||
import requests
|
||||
import configparser
|
||||
|
|
@ -110,5 +111,55 @@ class geofp(object):
|
|||
else:
|
||||
worldmap.render()
|
||||
|
||||
def plot_world2(self,title='Map', label='# Elements', filename='base_file', save=True):
|
||||
'''plot a fancy map with heat information '''
|
||||
from iso3166 import countries
|
||||
ct = Counter(self.members.country_code.values.tolist())
|
||||
del ct[None]
|
||||
|
||||
locations=[]
|
||||
z=[]
|
||||
names=[]
|
||||
for k in ct.keys():
|
||||
try:
|
||||
country=countries.get(k)
|
||||
locations.append(country[2])
|
||||
z.append(ct[k])
|
||||
names.append(country[0])
|
||||
except:
|
||||
continue
|
||||
|
||||
data = [ dict(
|
||||
type = 'choropleth',
|
||||
locations = pd.Series(locations) ,
|
||||
z = pd.Series(z),
|
||||
text = pd.Series(names),
|
||||
autocolorscale = True,
|
||||
reversescale = False,
|
||||
marker = dict(
|
||||
line = dict (
|
||||
color = 'rgb(180,180,180)',
|
||||
width = 0.5
|
||||
) ),
|
||||
colorbar = dict(
|
||||
title = label),
|
||||
) ]
|
||||
|
||||
layout = dict(
|
||||
title = title,
|
||||
geo = dict(
|
||||
showframe = False,
|
||||
showcountries = True,
|
||||
showcoastlines = False,
|
||||
projection = dict(
|
||||
type = 'Mercator'
|
||||
)
|
||||
)
|
||||
)
|
||||
fig = dict( data=data, layout=layout )
|
||||
return py.plot(fig,filename=filename )
|
||||
|
||||
|
||||
|
||||
def plot_heat(self,title):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from datetime import datetime
|
|||
|
||||
if __name__=='__main__':
|
||||
gp=geofp('myconfig.cfg')
|
||||
df=gp.ask_byCountry(datetime(2017,1,1))
|
||||
gp.plot_world(title='Fedora Ask',label='ask updates since January one, 2017',filename='ask.svg')
|
||||
df.to_csv('ask.csv')
|
||||
df=gp.all_fedorians(datetime(2017,1,1))
|
||||
print("Follow the link")
|
||||
print(gp.plot_world2(title='Fedora Active contributors since 01/01/2017',label='Active Contributors',filename='Fedora-Contributors'))
|
||||
df.to_csv('AllFedorians.csv')
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
pandas
|
||||
numpy
|
||||
pygal
|
||||
iso3166
|
||||
plotly
|
||||
fedora
|
||||
fedmsg
|
||||
ConfigParser
|
||||
fedmsg-meta-fedora-infrastructure
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue