def make_wordcloud_plot(show, title, best, worst, fname): logging.info("Making wordcloud for %s..." % show.title) net = Net() extra_stopwords = re.sub(r"[^\w]", " ", show.title.lower()).split() best_wordcloud = _get_wordcloud(net.get_reviews(best.imdb_id), extra_stopwords) worst_wordcloud = _get_wordcloud(net.get_reviews(worst.imdb_id), extra_stopwords) logging.info("Plotting...") fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(20, 12), facecolor=None) st = fig.suptitle(title, fontsize=Constants.TITLE_SIZE) st.set_y(0.97) ax1.set_title(Formatters.format_episode_title(best), fontsize=Constants.SUBTITLE_SIZE) ax1.imshow(best_wordcloud) ax1.axis("off") ax2.set_title(Formatters.format_episode_title(worst), fontsize=Constants.SUBTITLE_SIZE) ax2.imshow(worst_wordcloud) ax2.axis("off") plt.subplots_adjust(top=0.85) plt.tight_layout(pad=0) Saver.savefig(Constants.CLOUD_OUTPUT_DIR, fname) logging.info("Done!")
def _plot_ratings(director, fig, ax, save=False): data = [m.rating for m in director.movie_list] titles = [m.title for m in director.movie_list] _plot(fig, ax, data, titles, Constants.COLORS[0]) insights = DirectorInsights(director) _format_footnote_movies(ax, insights) if save: Saver.savefig(Constants.DIRECTOR_OUTPUT_DIR, director.slug + "-rating")
def plot_one_director(director): logging.info("Plotting movies for %s..." % director.name) fig, ax1 = plt.subplots(**_subplot_args(len(director.movie_list))) ax1.set_ylabel("movie rating", fontsize=Constants.LABEL_SIZE) ax1.set_xlabel("movie budget", fontsize=Constants.LABEL_SIZE) _plot_scatter(director, fig, ax1) logging.info("Done!") Saver.savefig(Constants.DIRECTOR_OUTPUT_DIR, director.slug)
def _plot_budget(director, fig, ax, save=False): insights = DirectorInsights(director) data = [m.budget for m in insights.movies_with_budget] titles = [m.title for m in insights.movies_with_budget] _plot(fig, ax, data, titles, Constants.COLORS[2]) formatter = ticker.FuncFormatter(lambda x, pos: '$%1.1fM' % (x * 1e-6)) ax.yaxis.set_major_formatter(formatter) if save: Saver.savefig(Constants.DIRECTOR_OUTPUT_DIR, director.slug + "-budget")
def _plot_boxoffice(director, fig, ax, save=False): insights = DirectorInsights(director) data = [m.boxoffice_worldwide for m in insights.movies_with_boxoffice] titles = [m.title for m in insights.movies_with_boxoffice] _plot(fig, ax, data, titles, Constants.COLORS[3]) formatter = ticker.FuncFormatter(lambda x, pos: '$%1.1fM' % (x * 1e-6)) ax.yaxis.set_major_formatter(formatter) # TODO(ncteisen): format footer if save: Saver.savefig(Constants.DIRECTOR_OUTPUT_DIR, director.slug + "-boxoffice")
def _plot_runtime(director, fig, ax, save=False): insights = DirectorInsights(director) data = [m.runtime for m in insights.movies_with_runtime] titles = [m.title for m in insights.movies_with_runtime] _plot(fig, ax, data, titles, Constants.COLORS[1]) formatter = ticker.FuncFormatter(lambda x, pos: '%d min' % x) ax.yaxis.set_major_formatter(formatter) insights = DirectorInsights(director) _format_footnote_movies_runtime(ax, insights) if save: Saver.savefig(Constants.DIRECTOR_OUTPUT_DIR, director.slug + "-runtime")
def _plot(show, fig, ax, save=False): xlabels = [] gx, gy = [], [] for season in show.season_list: if not season.episode_list: continue x = list(map(lambda e: e.index, season.episode_list)) y = list(map(lambda e: e.score, season.episode_list)) xlabels.extend(map(lambda e: e.label, season.episode_list)) gx.extend(x) gy.extend(y) # Plots the interpolation of season.episode_list for each season. if (season.episode_count > Constants.SPLINE_K): sp_x = np.linspace( season.episode_list[0].index, season.episode_list[-1].index, len(season.episode_list) * 10) sp_y = interpolate.make_interp_spline( x, y, k=Constants.SPLINE_K)(sp_x) ax.plot(sp_x, sp_y) # Plots the per season trend z = np.polyfit(x, y, deg=1) p = np.poly1d(z) ax.scatter(x, y) ax.plot(x, p(x), color=Constants.MIDDLEGROUND) # Plots the overall show trend. gz = np.polyfit(gx, gy, deg=1) gp = np.poly1d(gz) ax.plot(gx, gp(gx), color=Constants.FOREGROUND) insights = ShowInsights(show) _format_footnote_episodes(ax, insights) # Ticks ax.set_xticks(range(1, len(xlabels) + 1)) ax.set_xticklabels(xlabels, rotation=90) if save: Saver.savefig(Constants.GRAPH_OUTPUT_DIR, show.slug)
def plot_two_shows(show1, show2): logging.info("Plotting %s VS %s..." % (show1.title, show2.title)) fig, (ax1, ax2) = plt.subplots( 1, 2, **_subplot_args(show1.episode_count + show2.episode_count)) st = fig.suptitle( _format_compare_title( show1, show2), fontsize=Constants.TITLE_SIZE) st.set_y(0.97) ax1.set_ylabel("episode score", fontsize=Constants.LABEL_SIZE) _setup(show1, fig, ax1) _setup(show2, fig, ax2) _plot(show1, fig, ax1, False) _plot(show2, fig, ax2, False) plt.tight_layout() plt.subplots_adjust(top=0.85) fname = "{show1}--VS--{show2}".format(show1=show1.slug, show2=show2.slug) Saver.savefig(Constants.GRAPH_OUTPUT_DIR, fname) logging.info("Done!")
def _plot_season(show, season, fig, ax, save=False): xlabels = [] gx, gy = [], [] x = list(map(lambda e: e.number, season.episode_list)) y = list(map(lambda e: e.score, season.episode_list)) xlabels.extend(map(lambda e: e.label, season.episode_list)) gx.extend(x) gy.extend(y) # Set the color to be the same color it would have been in the overall # show plot. #NiceToHave color = Constants.COLORS[(season.number - 1) % len(Constants.COLORS)] # Plots the interpolation of season.episode_list for each season. if (season.episode_count > 3): sp_x = np.linspace(season.episode_list[0].number, season.episode_list[-1].number, len(season.episode_list) * 10) sp_y = interpolate.make_interp_spline(x, y, k=Constants.SPLINE_K)(sp_x) ax.plot(sp_x, sp_y, color=color) # Plots the per season trend z = np.polyfit(x, y, deg=1) p = np.poly1d(z) ax.scatter(x, y, color=color) ax.plot(x, p(x), color=Constants.MIDDLEGROUND) insights = SeasonInsights(season) _format_footnote_episodes(ax, insights) # Ticks ax.set_xticks(range(1, len(xlabels) + 1)) ax.set_xticklabels(xlabels, rotation=90) if save: Saver.savefig(Constants.GRAPH_OUTPUT_DIR, show.slug + "-season-" + str(season.number))