Skip to content

Commit 8b8783c

Browse files
authored
[ENH] best_on_top addition in plot_pairwise_scatter (#2655)
* Empty-Commit * best_on_top parameter added * changes
1 parent 05fb64c commit 8b8783c

File tree

3 files changed

+108
-35
lines changed

3 files changed

+108
-35
lines changed

Diff for: aeon/visualisation/results/_scatter.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def plot_pairwise_scatter(
4141
title=None,
4242
figsize=(8, 8),
4343
color_palette="tab10",
44+
best_on_top=True,
4445
):
4546
"""Plot a scatter that compares datasets' results achieved by two methods.
4647
@@ -66,6 +67,9 @@ def plot_pairwise_scatter(
6667
Size of the figure.
6768
color_palette : str, default = "tab10"
6869
Color palette to be used for the plot.
70+
best_on_top : bool, default=True
71+
If True, the estimator with better performance is placed on the y-axis (top).
72+
If False, the ordering is reversed.
6973
7074
Returns
7175
-------
@@ -129,7 +133,7 @@ def plot_pairwise_scatter(
129133
x, y = [min_value, max_value], [min_value, max_value]
130134
ax.plot(x, y, color="black", alpha=0.5, zorder=1)
131135

132-
# Choose the appropriate order for the methods. Best method is shown in the y-axis.
136+
# better estimator on top (y-axis)
133137
if (results_a.mean() <= results_b.mean() and not lower_better) or (
134138
results_a.mean() >= results_b.mean() and lower_better
135139
):
@@ -143,6 +147,11 @@ def plot_pairwise_scatter(
143147
second = results_b
144148
second_method = method_b
145149

150+
# if best_on_top is False, swap the ordering
151+
if not best_on_top:
152+
first, second = second, first
153+
first_method, second_method = second_method, first_method
154+
146155
differences = [
147156
0 if i - j == 0 else (1 if i - j > 0 else -1) for i, j in zip(first, second)
148157
]

Diff for: aeon/visualisation/results/tests/test_scatter.py

+13
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,19 @@ def test_plot_pairwise_scatter():
9191

9292
assert isinstance(fig, plt.Figure) and isinstance(ax, plt.Axes)
9393

94+
# best_on_top = False (reversed ordering)
95+
fig_false, ax_false = plot_pairwise_scatter(
96+
res[0],
97+
res[1],
98+
cls[0],
99+
cls[1],
100+
metric="accuracy",
101+
title="Test Plot best_on_top False",
102+
best_on_top=False,
103+
)
104+
plt.gcf().canvas.draw_idle()
105+
assert isinstance(fig_false, plt.Figure) and isinstance(ax_false, plt.Axes)
106+
94107
# Test error handling for metrics
95108
with pytest.raises(ValueError):
96109
plot_pairwise_scatter(

0 commit comments

Comments
 (0)