Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions analysis/cheung_variants/analysis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,28 @@

def make_deont_util_plot(scenario_name, plot_df, results_path):

plot_df = plot_df.copy()

# Normalize labels so Seaborn order always matches regardless of input dtype
for col in ["deontology_label", "utility_label"]:
plot_df[col] = plot_df[col].astype(str).str.strip()

plot_df["value"] = plot_df["value"].astype(float)

deontology_order = [
x for x in ["1", "2", "3"]
if x in plot_df["deontology_label"].dropna().unique().tolist()
]
utility_order = [
x for x in ["1", "2", "3"]
if x in plot_df["utility_label"].dropna().unique().tolist()
]

if not deontology_order:
deontology_order = sorted(plot_df["deontology_label"].dropna().unique().tolist())
if not utility_order:
utility_order = sorted(plot_df["utility_label"].dropna().unique().tolist())


# Two blue shades for the two measures
blue_palette = {
Expand All @@ -27,14 +49,15 @@ def make_deont_util_plot(scenario_name, plot_df, results_path):
errorbar="se",
capsize=0.12,
palette=blue_palette,
order=["1", "2", "3"],
order=deontology_order,
ax=axes[0],
)

axes[0].set_title(f"Mean Ratings ± SE by Deontology Label ({scenario_name})", pad=12)
axes[0].set_xlabel("Deontology Category")
axes[0].set_ylabel("Rating")
axes[0].set_xticklabels(["Low", "Medium", "High"])
label_map = {"1": "Low", "2": "Medium", "3": "High"}
axes[0].set_xticklabels([label_map.get(x, x) for x in deontology_order])
axes[0].grid(axis="y", linestyle="--", alpha=0.3)
axes[0].set_ylim(-100, 100)

Expand All @@ -52,15 +75,15 @@ def make_deont_util_plot(scenario_name, plot_df, results_path):
errorbar="se",
capsize=0.12,
palette=blue_palette,
order=["1", "2", "3"],
order=utility_order,
ax=axes[1],
)

axes[1].set_title(f"Mean Ratings ± SE by Utility Label ({scenario_name})", pad=12)
axes[1].set_xlabel("Utility Category")
axes[1].set_ylabel("")

axes[1].set_xticklabels(["Low", "Medium", "High"])
axes[1].set_xticklabels([label_map.get(x, x) for x in utility_order])
axes[1].set_ylim(-100, 100)

axes[1].grid(axis="y", linestyle="--", alpha=0.3)
Expand All @@ -71,4 +94,5 @@ def make_deont_util_plot(scenario_name, plot_df, results_path):

sns.despine()
plt.tight_layout()
plt.savefig(results_path / f"{scenario_name}_deont_util_comparison.png", dpi=300)
plt.savefig(results_path / f"{scenario_name}_deont_util_comparison.png", dpi=300)
plt.show()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading