def make_hex_svg(self, output_fname, show=False, draw_text=False): """ Outputs an SVG file of the hexgrid output_fname: the outputfilepath show: whether or not the output should be displayed in the ipython notebook draw_text: whether or not the id_col text should be drawn on the map """ self._initialize_grid() self._populate_new_grid() cg = Chorogrid(self.df, self.df[self.index_col].tolist(), ['#eeeeee'] * len(self.df), id_column=self.index_col) cg.draw_hex(draw_text=draw_text) cg.done(save_filename=output_fname, show=show) return
def plot_cloropleth_map(ls,interest,leg,year): mycolors = ['#b35806', '#f1a340', '#fee0b6', '#d8daeb', '#998ec3', '#542788'] mybin = Colorbin(ls, mycolors, proportional=True, decimals=None) state_info = pd.read_csv('chorogrid/databases/usa_states.csv') colors_by_state = mybin.colors_out font_colors_by_state = mybin.complements legend_colors = mybin.colors_in legend_labels = mybin.labels cg = Chorogrid('chorogrid/databases/usa_states.csv', states, colors_by_state) cg.set_title(str(year)+' H1b '+str(interest), font_dict={'font-size': 19}) cg.set_legend(legend_colors, legend_labels, title=leg) #cg = Chorogrid('chorogrid/databases/usa_states.csv', states, colors_by_state) cg.draw_map(spacing_dict={'legend_offset': [-150,-25]}) #cg.draw_squares(spacing_dict={'margin_right': 150}) cg.done(show=False, save_filename = str(year)+' H1b '+str(interest))
def plot_states(states, values, title="", legend="", colors=DEFAULT_COLORS, complements=DEFAULT_COMPLEMENTS, font={}, spacing={}, decimals=1, shape="hex", quantile=False): states = [_get_state(state) for state in states] states, values = zip(*[(state, value) for state, value in zip(states, values) if state in STATE_ABBREVS.values()]) if quantile: values = pd.qcut(values, 6, [-20, -10, -1, 1, 10, 20]) # Colors cbin = Colorbin(values, colors, proportional=True, decimals=None) cbin.set_decimals(decimals) cbin.recalc(fenceposts=True) cbin.calc_complements(0.0, *complements) # Choropleth cg = Chorogrid(STATE_FILEPATH, states, cbin.colors_out) cg.set_title(title, font_dict=font) if quantile: labels = _quantile_labels(len(colors)) else: labels = cbin.labels cg.set_legend(cbin.colors_in, labels, title=legend) # Draw draw_fn = { "hex": cg.draw_hex, "square": cg.draw_squares, "multihex": cg.draw_multihex, "multisquare": cg.draw_multisquare, "map": cg.draw_map }[shape] draw_fn(spacing_dict=spacing) return cg.done(show=True)
def plot_counties(fips, values, title="", legend="", colors=DEFAULT_COLORS, complements=DEFAULT_COMPLEMENTS, font={}, spacing={}, decimals=1, quantile=False, statelines=False): fips, values = zip(*[(fip, value) for fip, value in zip(fips, values) if fip in COUNTY_IDS]) if quantile: values = pd.qcut(values, 6, [-20, -10, -1, 1, 10, 20]) # Colors cbin = Colorbin(values, colors, proportional=True, decimals=None) cbin.set_decimals(decimals) cbin.recalc(fenceposts=True) cbin.calc_complements(0.0, *complements) # Choropleth cg = Chorogrid(COUNTY_FILEPATH, fips, cbin.colors_out, id_column="fips_integer") cg.set_title(title, font_dict=font) if quantile: labels = _quantile_labels(len(colors)) else: labels = cbin.labels cg.set_legend(cbin.colors_in, labels, title=legend) # Draw cg.draw_map(spacing_dict=spacing) if statelines: with open(STATELINES_FILEPATH, 'r') as f: statelines = f.read() cg.add_svg(statelines) return cg.done(show=True)
def make_hex_svg(self, output_fname=None, show=False, draw_text=False): """ Outputs an SVG file of the hexgrid output_fname: the outputfilepath show: whether or not the output should be displayed in the ipython notebook draw_text: whether or not the id_col text should be drawn on the map """ if "/" in output_fname and not os.path.isdir( output_fname[:output_fname.rfind('/')] ): #check if outputfilepath directory exists raise IOError('The directory specified does not exist') self._initialize_grid() self._populate_new_grid() cg = Chorogrid(self.df, self.df[self.index_col].tolist(), ['#eeeeee'] * len(self.df), id_column=self.index_col) cg.draw_hex(draw_text=draw_text) cg.done(save_filename=output_fname, show=show) self.total_width = cg.total_width self.total_height = cg.total_height self.svgstring = cg.svgstring return
colors = [ '#fff5eb', '#fee6ce', '#fdd0a2', '#fdae6b', '#fd8d3c', '#f16913', '#d94801', '#8c2d04' ] chBin = Colorbin(dfStateUN['Unemployment'], colors, proportional=True, decimals=None) chBin.set_decimals(1) chBin.recalc(fenceposts=True) chBin.fenceposts colors_out = chBin.colors_out legend_colors = chBin.colors_in legend_labels = chBin.labels cg = Chorogrid( 'X:\\Documents\\Research\\Tools\\Python\\chorogrid-master\\chorogrid\\databases\\usa_states.csv', list(dfStateUN['State']), colors_out) cg.set_title('Average Unemployment by State (%)', font_dict={'font-size': 16}) cg.set_legend(legend_colors, legend_labels, title='% Unemployment') cg.draw_map(spacing_dict={'margin_right': 400}) cg.done(show=True) ####### Import the LC Data ####### path = 'D:\\Andrew\\VM_Storage\\LendingClub\\LoanStats3.csv' dfListings = pd.read_csv(path) cat_names = { 'Fully Paid': 1, 'Charged Off': 0,