def plot_contrib(contribs): """Unpack and plot candidates' contributions by state in different subplots""" rows = 4 cols = math.ceil(len(contribs) / rows) pix = 0 for candidate, contrib in contribs.iteritems(): subplot = p.gcf().add_subplot(rows, cols, pix) for state, amount in contrib.iteritems(): m.draw_state(subplot, m.get_statename(state), color=donation_color(amount)) # Make it pretty subplot.set_title(candidate) subplot.set_xticks([]) subplot.set_yticks([]) pix += 1
def plot_contrib(contribs): """Unpack and plot candidates' contributions by state in different subplots""" rows = 4 cols = math.ceil(len(contribs)/rows) pix = 0 for candidate, contrib in contribs.iteritems(): subplot = p.gcf().add_subplot(rows, cols, pix) for state, amount in contrib.iteritems(): m.draw_state(subplot, m.get_statename(state), color = donation_color(amount)) # Make it pretty subplot.set_title(candidate) subplot.set_xticks([]) subplot.set_yticks([]) pix += 1
subplot.plot(xx, y1, xx, y2) subplot = fig.add_subplot(323) boxdata = [[random.randint(0, random.randint(20, 60)) for ix in xrange(20)] \ for ix in xrange(3)] subplot.boxplot(boxdata) subplot = fig.add_subplot(324) subplot.scatter(xx, y1, marker = 'o', color='orange', linewidth=0) import sys sys.path.append('../../resources/util') import map_util as m import json subplot = fig.add_subplot(325) with open('../../datasets/geo/id-counties.json') as counties_file: counties = json.load(counties_file) for county in counties: m.draw_county(subplot, county) subplot = fig.add_subplot(326) with open('../../datasets/geo/id-states.json') as states_file: states = json.load(states_file) for state in states: m.draw_state(subplot, state) p.show()
familar to me. """ # Choropleth plot sys.path.append("dataiap/resources/util") import map_util as m fig = plt.figure() # Map of Counties # data is a list of strings that contain fips values county = fig.add_subplot(211) data = json.load(file('dataiap/datasets/geo/id-counties.json')) for fips in data: m.draw_county(county, fips) # Map of States s = fig.add_subplot(212) data = json.load(file('dataiap/datasets/geo/id-states.json')) for state in data: m.draw_state(s, state) # # this creates an array of grey colors from white to black # colors = ['0','1','2','3','4','5','6','7','8','9','a', 'b', 'c', 'd', 'e', 'f'] # colors = map(lambda s: '#%s' % (s*6), colors) # colors.sort(reverse=True) # # # assume MAXDONATION was defined # # assume curdonation is the donation to pick a color for # ratio = (curdonation/float(MAXDONATION)) # color_idx = int( ratio * (len(colors) - 1) ) # colors[color_idx]