Created
June 2, 2016 12:32
-
-
Save kidpixo/290a76e3b15f3bfecc0ff794e36b8ae4 to your computer and use it in GitHub Desktop.
simple visualisation of twofactorauth.org data with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
# load the sections descriptions | |
sections = open("sections.yml", "r") | |
docs = yaml.load(sections) | |
doc_list = [i['id'] for i in docs] | |
sections.close() | |
# read the single files | |
data = {} | |
for section in doc_list: | |
section_file = open(section+'.yml', "r") | |
section_data = yaml.load(section_file) | |
data[section] = section_data['websites'] | |
section_file.close() | |
# collect the data | |
plot_data = {} | |
plot_data['len']={} | |
plot_data['yes']={} | |
plot_data_yes = {} | |
for k,v in data.iteritems(): | |
plot_data['len'][k]=len(v) | |
plot_data['yes'][k]=sum(( i['tfa'] for i in v )) | |
import matplotlib | |
from matplotlib import pyplot as plt | |
%matplotlib | |
plt.bar(range(len(plot_data['len'])), plot_data['len'].values(), align='center',color='red',width=1, lw=0) | |
plt.bar(range(len(plot_data['yes'])), plot_data['yes'].values(), align='center',color='green',width=1,lw=0) | |
plt.gca().yaxis.set_major_locator(plt.NullLocator()) | |
plt.xticks(range(len(plot_data['len'])), [i[0:] for i in plot_data['len'].keys()], rotation=90); | |
plt.xlim([-0.5,len(plot_data['len'])-0.5]) | |
plt.tight_layout() | |
plt.savefig('yes_no.png') | |
plt.bar(range(len(plot_data['len'])), [1]*len(plot_data['len']), align='center',color='red',width=1, lw=0) | |
plt.bar(range(len(plot_data['yes'])), [y/float(l) for l,y in zip(plot_data['len'].values(),plot_data['yes'].values())], align='center',color='green',width=1,lw=0) | |
plt.gca().yaxis.set_major_locator(plt.NullLocator()) | |
plt.xticks(range(len(plot_data['len'])), [i[0:] for i in plot_data['len'].keys()], rotation=90); | |
plt.xlim([-0.5,len(plot_data['len'])-0.5]) | |
plt.tight_layout() | |
plt.savefig('yes_no_perc.png') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment