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 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
mycolors = ['#e0e9f0', '#c1d4e2', '#a3bed4', '#84a9c6','#6694b8', '#517693', '#3d586e'] mybin = Colorbin(df['percentage'], mycolors, proportional=True, decimals=None) mybin.set_decimals(1) mybin.recalc(fenceposts=True) mybin.fenceposts mybin.calc_complements(0.5, '#e0e0e0', '#101010') states = list(df.index) 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('Number of P2P Loans Normalized by State Population', font_dict={'font-size': 16}) cg.set_legend(legend_colors, legend_labels, title='# of Loans scaled by population') cg.draw_hex(spacing_dict={'margin_right': 210}, font_colors=font_colors_by_state) cg.done(show=True) # 1.2 number of loans issued by states - choropleth map df = listings.groupby(['BorrowerState']).ListingAmountFunded.count() mycolors = ['#e0e9f0', '#c1d4e2', '#a3bed4', '#84a9c6','#6694b8', '#517693', '#3d586e'] mybin = Colorbin(df, mycolors, proportional=True, decimals=None) mybin.set_decimals(1) mybin.recalc(fenceposts=True) mybin.fenceposts mybin.calc_complements(0.5, '#e0e0e0', '#101010') states = list(df.index) colors_by_state = mybin.colors_out font_colors_by_state = mybin.complements legend_colors = mybin.colors_in