Skip to content

Commit

Permalink
Add adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilwoodruff committed Dec 10, 2024
1 parent 8198ee3 commit dc94648
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 9 additions & 2 deletions policyengine/utils/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down
10 changes: 7 additions & 3 deletions policyengine/utils/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ 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",
repo_filename="local_authorities_2021.csv",
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)
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit dc94648

Please sign in to comment.