From dc94648761c09490c8aab1baef041527aeb779e9 Mon Sep 17 00:00:00 2001 From: Nikhil Woodruff Date: Tue, 10 Dec 2024 15:02:57 +0000 Subject: [PATCH] Add adjustments --- .../macro/single/gov/local_areas/local_authorities.py | 2 +- .../gov/local_areas/parliamentary_constituencies.py | 2 +- policyengine/utils/charts.py | 11 +++++++++-- policyengine/utils/maps.py | 10 +++++++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/policyengine/outputs/macro/single/gov/local_areas/local_authorities.py b/policyengine/outputs/macro/single/gov/local_areas/local_authorities.py index eceed6e..9846fba 100644 --- a/policyengine/outputs/macro/single/gov/local_areas/local_authorities.py +++ b/policyengine/outputs/macro/single/gov/local_areas/local_authorities.py @@ -51,7 +51,7 @@ def local_authorities( sim = simulation.selected_sim original_hh_weight = sim.calculate("household_weight").values - metric(simulation.selected) + metric(sim) for constituency_id in range(weights.shape[0]): sim.set_input( diff --git a/policyengine/outputs/macro/single/gov/local_areas/parliamentary_constituencies.py b/policyengine/outputs/macro/single/gov/local_areas/parliamentary_constituencies.py index ba4dbc6..fcbbf93 100644 --- a/policyengine/outputs/macro/single/gov/local_areas/parliamentary_constituencies.py +++ b/policyengine/outputs/macro/single/gov/local_areas/parliamentary_constituencies.py @@ -51,7 +51,7 @@ def parliamentary_constituencies( sim = simulation.selected_sim original_hh_weight = sim.calculate("household_weight").values - metric(simulation.selected) + metric(sim) for constituency_id in range(weights.shape[0]): sim.set_input( diff --git a/policyengine/utils/charts.py b/policyengine/utils/charts.py index 2b9de31..c624d45 100644 --- a/policyengine/utils/charts.py +++ b/policyengine/utils/charts.py @@ -45,11 +45,15 @@ def get_version_number(package): return pkg_resources.get_distribution(package).version -def format_fig(fig: go.Figure, country: str = "uk") -> go.Figure: +def format_fig( + fig: go.Figure, country: str = "uk", add_zero_line: bool = False +) -> go.Figure: """Format a plotly figure to match the PolicyEngine style guide. Args: fig (go.Figure): A plotly figure. + country (str): The country for which the style guide should be applied. + add_zero_line (bool): Whether to add a zero line to the plot. Returns: go.Figure: A plotly figure with the PolicyEngine style guide applied. @@ -70,7 +74,10 @@ def format_fig(fig: go.Figure, country: str = "uk") -> go.Figure: paper_bgcolor=LIGHT_LIGHT_GRAY, # set paper background color to white # No white grid marks xaxis=dict(gridcolor=LIGHT_LIGHT_GRAY, zerolinecolor=LIGHT_LIGHT_GRAY), - yaxis=dict(gridcolor=LIGHT_LIGHT_GRAY, zerolinecolor=DARK_GRAY), + yaxis=dict( + gridcolor=LIGHT_LIGHT_GRAY, + zerolinecolor=DARK_GRAY if add_zero_line else LIGHT_LIGHT_GRAY, + ), ) fig.add_layout_image( diff --git a/policyengine/utils/maps.py b/policyengine/utils/maps.py index a93a6ce..0885748 100644 --- a/policyengine/utils/maps.py +++ b/policyengine/utils/maps.py @@ -15,6 +15,8 @@ def plot_hex_map(value_by_area_name: dict, location_type: str) -> dict: local_folder=None, version=None, ) + x_bounds = [30, 85] + y_bounds = [-50, 2] elif location_type == "local_authorities": area_names_file_path = download( repo="policyengine/policyengine-uk-data", @@ -22,6 +24,8 @@ def plot_hex_map(value_by_area_name: dict, location_type: str) -> dict: local_folder=None, version=None, ) + x_bounds = [-20, 25] + y_bounds = [-10, 35] else: raise ValueError("Invalid location_type: " + location_type) area_names = pd.read_csv(area_names_file_path) @@ -65,11 +69,11 @@ def plot_hex_map(value_by_area_name: dict, location_type: str) -> dict: yaxis_title="", xaxis_range=[expanded_lower_x_range, expanded_upper_x_range], yaxis_range=[ - constituency_names["y"].min(), - constituency_names["y"].max(), + area_names["y"].min(), + area_names["y"].max(), ], ).update_traces(marker_size=10).update_layout( - xaxis_range=[30, 85], yaxis_range=[-50, 2] + xaxis_range=x_bounds, yaxis_range=y_bounds ) x_min = fig.data[0]["marker"]["color"].min()