def create_figure_with_boxplot(title, use_legend): fig = plt.figure(figsize=(7 + 3 * use_legend, 4), dpi=100, tight_layout=True, facecolor='w') matplotlib.rcParams.update({'font.size': 10}) gs = gridspec.GridSpec(1, 3, width_ratios=[3 if use_legend else .2, 6, 1]) # gs = gridspec.GridSpec(1, 3, width_ratios=[.2, 6, 1]) time_graph = fig.add_subplot(gs[1], title=title, axisbg='#EEEEEE') time_graph.set_xlabel('Days') boxplot_graph = fig.add_subplot(gs[2], sharey=time_graph, axisbg='#EEEEEE') # http://stackoverflow.com/questions/4209467/matplotlib-share-x-axis-but-dont-show-x-axis-tick-labels-for-both-just-one # boxplot_graph.locator_params(nbins=4) # limiting the number of y-axis ticks was causing an intermittent crash. # try/except this if you want it plt.setp(boxplot_graph.get_yticklabels(), visible=False) for axis in [time_graph, boxplot_graph]: rstyle(axis) time_graph.grid(False) return boxplot_graph, fig, gs, time_graph
def population_results_map(): """Creates a map that summarizes the range of outcomes amongst all iterations of a simulation. Estimated time = Unit.objects.count() / 650 in seconds. """ start_time = time() fig= Figure(figsize=(60,52), frameon=True, tight_layout=True) ax = fig.add_subplot(1,1,1, axisbg='#EEEEEE') ax.grid(color='white', linestyle='solid') rstyle(ax) queryset = Unit.objects.all() # It might be faster to request a flat value list and then construct new tuples based on that latlong = [(u.latitude, u.longitude, u.unitstats.cumulative_infected, u.unitstats.cumulative_vaccinated, u.unitstats.cumulative_destroyed, u.unitstats.cumulative_zone_focus, u.initial_size, ) for u in queryset] total_iterations = float(len(list_of_iterations())) latitude, longitude, infected, vaccinated, destroyed, zone_focus, herd_size = zip(*latlong) zone_blues, red_infected, green_vaccinated = define_color_mappings() graph_zones(ax, latitude, longitude, total_iterations, zone_blues, zone_focus) graph_states(ax, latitude, longitude, total_iterations, infected, vaccinated, destroyed) neutral_longitude = [entry[1] for entry in latlong if not any(x > 0 for x in (entry[2], entry[3], entry[4]))] neutral_latitude = [entry[0] for entry in latlong if not any(x > 0 for x in (entry[2], entry[3], entry[4]))] # to ensure zero occurrences has a different color uninvolved = ax.scatter(neutral_longitude, neutral_latitude, marker='s', s=[min(max(0.25, size / 100), 1000) for size in herd_size], color=(0.2, 0.2, 0.2, 1.0), zorder=1000) Results.graphing.crop_to_fit_map(ax) print("Population Map took %i seconds" % int(time() - start_time)) return fig