def prettifyLife(ax: mltax.Axes, N: int) -> None: if N <= 50: ax.grid() ax = plt.gca() ax.set_xticks(np.arange(-.5, N - 1, 1)) ax.set_yticks(np.arange(-.51, N - 1, 1)) ax.set_xticklabels(np.arange(0, N, 1)) ax.set_yticklabels(np.arange(0, N, 1)) elif N > 50 and N < 80: ax.grid() ax = plt.gca() labels = [" " for x in range(N)] plt.xticks(np.arange(-.5, N - 1, 1), labels) plt.yticks(np.arange(-.51, N - 1, 1), labels)
def format_plot_3(plt_3: Axes, x_vals: List[int], state_info_list: List[StateInfo]) -> BarContainer: """Adjust all properties of plot 3 to make it look nice. Add the x & y ticks, format those ticks, set the title, and place the text on the plot for the priority num plot. Parameters ---------- plt_3 : `Axes` The object that describes the graph x_vals : `List[int]` The list of ints that shows the states' position's state_info_list : `List[StateInfo]` Continually updated list of state calculation info Returns ------- `BarContainer` The objects describing the plotted bars """ state_names = extract_state_names(state_info_list) priority_list = extract_priority(state_info_list) plt_3_bars: BarContainer = plt_3.bar(x_vals, priority_list, align="center", color="g") plt_3.set_xticks(x_vals) plt_3.set_xticklabels(state_names, rotation="vertical") y_formatter: FuncFormatter = FuncFormatter(comma_format_int()) plt_3.set_ylabel("Priority value") plt_3.set_yscale("log") plt_3.get_yaxis().set_major_formatter(y_formatter) plt_3.text(0.3, 0.9, "Highlighted, is the state with the highest priority value", transform=plt_3.transAxes) plt_3.grid(axis="y", which="major", lw=2) plt_3.grid(axis="y", which="minor", lw=0.75) plt_3.grid(axis="x", lw=0.75) plt_3.set_title("Priority values per state") return plt_3_bars
def format_plot_2(plt_2: Axes, x_vals: List[int], state_info_list: List[StateInfo]) -> BarContainer: """Adjust all properties of plot 2 to make it look nice. Add the x & y ticks, format those ticks, set the title, and place the text on the plot for the number of reps plot. Parameters ---------- plt_2 : `Axes` The object that describes the graph x_vals : `List[int]` The list of ints that shows the states' position's state_info_list : `List[StateInfo]` Continually updated list of state calculation info Returns ------- `BarContainer` The objects describing the plotted bars """ state_names = extract_state_names(state_info_list) reps_list = extract_reps(state_info_list) plt_2_bars: BarContainer = plt_2.bar(x_vals, reps_list, align="center", color="r") plt_2.set_xticks(x_vals) plt_2.set_xticklabels(state_names, rotation="vertical") y_axis = plt_2.get_yaxis() minor_loc = MultipleLocator(5) y_axis.set_minor_locator(minor_loc) plt_2.set_ylabel("Representatives") plt_2.set_ylim(top=60, bottom=0) plt_2.grid(axis="y", which="major", lw=2) plt_2.grid(axis="y", which="minor", lw=0.75) plt_2.grid(axis="x", lw=0.75) plt_2.set_title("Representatives per state") return plt_2_bars
def format_plot_1(plt_1: Axes, x_vals: List[int], state_info_list: List[StateInfo]) -> PlotProps: """Adjust all properties of plot 1 to make it look nice. Add the x & y ticks, format those ticks, set the title, draw the mean line, and place the text on the plot for the pop_per_rep plot. Parameters ---------- plt_1 : `Axes` The object that describes the graph x_vals : `List[int]` The list of ints that shows the states' positions state_info_list : `List[StateInfo]` Continually updated list of state calculation info Returns ------- `PlotProps` A tuple of the plotted bars, text, and line objects """ state_names = extract_state_names(state_info_list) pop_per_rep_list = extract_pop_per_rep(state_info_list) plt_1_bars: BarContainer = plt_1.bar(x_vals, pop_per_rep_list, align="center") plt_1.set_xticks(x_vals) plt_1.set_xticklabels(state_names, rotation="vertical") y_formatter = FuncFormatter(comma_format_int()) plt_1.set_ylabel("People/Representative") plt_1.set_yscale("log") plt_1.get_yaxis().set_major_formatter(y_formatter) plt_1.set_title("People per representative per state") plt_1.grid(axis="y", which="major", lw=2) plt_1.grid(axis="y", which="minor", lw=0.75) plt_1.grid(axis="x", lw=0.75) mean_pop_per_seat: float = np.mean(pop_per_rep_list) std_dev_pop_per_seat: float = np.std(pop_per_rep_list) range_pop_per_seat: float = max(pop_per_rep_list) - min(pop_per_rep_list) geo_mean_pop_per_seat: float = geometric_mean(pop_per_rep_list) res_dict: PlotTextDict = {} res_dict["seat_txt"] = plt_1.text(0.25, 0.75, f"Seat# 1", transform=plt_1.transAxes) res_dict["state_txt"] = plt_1.text(0.15, 0.85, "State: ", transform=plt_1.transAxes) res_dict["mean_txt"] = plt_1.text(0.45, 0.75, f"Mean: {mean_pop_per_seat:,.2f}", transform=plt_1.transAxes) res_dict["std_dev_txt"] = plt_1.text( 0.35, 0.85, f"Std. Dev. {std_dev_pop_per_seat:,.2f}", transform=plt_1.transAxes) res_dict["range_txt"] = plt_1.text(0.70, 0.75, f"Range: {range_pop_per_seat:,.2f}", transform=plt_1.transAxes) res_dict["geo_mean_txt"] = plt_1.text( 0.6, 0.85, f"Geo. Mean: {geo_mean_pop_per_seat:,.2f}", transform=plt_1.transAxes) mean_line: Line2D = plt_1.axhline(y=mean_pop_per_seat, xmin=0.0, xmax=1.0, color="r") return (plt_1_bars, mean_line, res_dict)