def venue_menu(self): """ Menu for venue visualizations. """ print (u"\n░▒▓█ ■ Select a visualization of the inter-venue semantic distances.\n") print (u"░▒▓█ (1) 30 Venue Heatmap - top 30 venues") print (u"░▒▓█ (2) 30 Venue MDS - top 30 venues") print (u"░▒▓█ (3) 600 Venue MDS - top 600 venues") print (u"░▒▓█ (4) MDS - top 40 venues from each of top 5 categories") print (u"░▒▓█ (5) Temporal view. - top 2 venues from top 5 categories") print (u"░▒▓█ (6) ■ back to main menu ■\n") pick_vis = get_input("> ", int, 1, 6) if pick_vis is 1: print u"\n░░▒▒▓█ ■ You must close graph in order to continue using program." self.driver.vis_heatmap(self.driver.dist_matrix, [ven.name for ven in self.driver.vens]) self.venue_menu() elif pick_vis is 2: print u"\n░░▒▒▓█ ■ You must close graph in order to continue using program." self.driver.vis_MDS(self.driver.dist_matrix, [ven.name for ven in self.driver.vens]) self.venue_menu() elif pick_vis is 3: print u"\n░░▒▒▓█ ■ You must close graph in order to continue using program." super_dist_matrix = self.driver.compare_venues(self.driver.vens) self.driver.vis_super_MDS(super_dist_matrix) self.venue_menu() elif pick_vis is 4: print u"\n░░▒▒▓█ ■ You must close graph in order to continue using program." self.driver.vis_super_cat_MDS(5) self.venue_menu() elif pick_vis is 5: cat_list, ven_list = sq.venues_from_top_n_categories(2, 5) for v in ven_list: self.driver.temporal_weekday_single_ven(v.id) self.venue_menu() elif pick_vis is 6: self.main_menu()
def vis_super_cat_MDS(self, n=5, fout=None): """ Displays MDS graph of venues in the top n categories :param n: number of top categories to include :type n: int :param fout: save graph to file :type fout: str :return: None :rtype: None """ category_list, venue_list = sq.venues_from_top_n_categories(200 / n, n) ven_dmatrix = self.compare_venues(venue_list) # make dict to assign numbers to category names for coloring in graph category_name2num = {} for i, category_name in enumerate(category_list): category_name2num[category_name] = i with plt.style.context("ggplot"): # setup plot figure fig, ax = plt.subplots(subplot_kw=dict(axisbg="#EEEEEE")) ax.grid(color="white", linestyle="solid", linewidth=2) fig = plt.gcf() fig.set_dpi(100) fig.set_size_inches((8.0, 8.0), forward=True) plt.subplots_adjust(left=0.10, bottom=0.10, right=0.95, top=0.95) plt.gca().grid(True) plt.axis([-1.0, 1.0, -1.0, 1.0]) ttl = plt.title("MDS: Venues from Top {} Categories".format(n)) plt.xlabel("Click on dots to toggle labels.\nDot size depends on total # of shouts.") # get MDS coordinates for venues myMDS = MDS(2, verbose=0, n_jobs=-1, dissimilarity="precomputed") myMDS.fit(ven_dmatrix) points = myMDS.embedding_ # add column to points to hold venue categories # TODO: higher-level categories from Foursquare's categories json points = np.c_[points, np.zeros(len(points))] # for each venue, normalize category number between 0-1 and store in new column. for i, point in enumerate(points): point[2] = float(category_name2num[venue_list[i].cat_name]) / len(category_list) # plot the points x_vals = points[:, 0] y_vals = points[:, 1] point_colors = points[:, 2] sizes = [(30 * np.sqrt(ven.shout_count)) for ven in venue_list] annotes = [u"{name}\n{category}".format(name=v.name, category=v.cat_name) for v in venue_list] my_plot = plt.scatter( x_vals, y_vals, marker="o", facecolor=point_colors, s=sizes, cmap=plt.get_cmap("prism"), edgecolor="#303030", linewidth=0.5, alpha=0.45, ) # connect mouse-click action af = AnnoteFinder(x_vals, y_vals, annotes) plt.connect("button_press_event", af) # adjust tick labels plt.tick_params(axis="both", which="major", labelsize=7, color="gray") plt.tick_params(axis="both", which="minor", labelsize=7, color="gray") # turn off ticks ax = plt.gca() for t in ax.xaxis.get_major_ticks(): t.tick1On = False t.tick2On = False for t in ax.yaxis.get_major_ticks(): t.tick1On = False t.tick2On = False if fout is None: plt.show() else: fig.savefig(fout)