Skip to content

Instantly share code, notes, and snippets.

@leggitta
Last active June 9, 2017 21:20
Show Gist options
  • Save leggitta/02f15e5cc7f1bee20b0a016e6881cbc3 to your computer and use it in GitHub Desktop.
Save leggitta/02f15e5cc7f1bee20b0a016e6881cbc3 to your computer and use it in GitHub Desktop.
from bokeh.plotting import figure, show
from bokeh.io import output_file
import numpy as np
import pandas as pd
output_file('n_filings.html')
# read the filing data
filings = pd.read_csv('filings.csv')
# compute number of filings and names per committee id
n_filings = filings.groupby('fec_committee_id').filing_id.nunique()
n_names = filings.groupby('fec_committee_id').committee_name.nunique()
n_committees = len(n_filings)
# save the committee data
committee_data = pd.concat([n_filings, n_names], axis=1)
committee_data.columns = ('n_filings', 'n_names')
committee_data.to_csv('committee_data.csv')
# compute the log histogram
hist, edges = np.histogram(n_filings, bins=np.logspace(0, 3, 15))
# plot log histogram
fig = figure(
width=600, height=500, toolbar_location=None, x_axis_type="log",
title="Filings Per Committee", background_fill_color='oldlace')
fig.title.text_font = "times"
fig.title.text_font_size = "16pt"
fig.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
line_color='black', fill_color='seagreen')
fig.xaxis.axis_label = "Number of Filings"
fig.xaxis.axis_label_text_font = "times"
fig.xaxis.axis_label_text_font_size = "12pt"
fig.yaxis.axis_label = "Committee Count"
fig.yaxis.axis_label_text_font = "times"
fig.yaxis.axis_label_text_font_size = "12pt"
show(fig)
@leggitta
Copy link
Author

leggitta commented Jun 9, 2017

Generates the following plot ....

bokeh_plot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment