Skip to content

Commit d6ef312

Browse files
committed
Use 6:5 subplots and fixed Valley-Bowl axis limits
Make the subplots slightly wider than tall (box aspect 5/6), so that matplotlib's automatic ticks on the x-axis are as complete as on the y-axis instead of skipping values.
1 parent afb1ee5 commit d6ef312

5 files changed

Lines changed: 37 additions & 12 deletions

File tree

‎tests/trajectories/_constants.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,27 @@
9494
"xlim": (-0.125, 2.625),
9595
"ylim": (-0.425, 8.925),
9696
},
97+
"VB": {
98+
"xlim": (-21.0, 11.0),
99+
"ylim": (-21.0, 11.0),
100+
},
101+
"VB01": {
102+
"xlim": (-2.1, 1.1),
103+
"ylim": (-21.0, 11.0),
104+
},
105+
}
106+
107+
# Fixed xlim and ylim of the param plot, for objectives where fitting them to the content is not
108+
# wanted
109+
PLOT_PARAMS_LIMS = {
110+
"VB": {
111+
"xlim": (-10.5, 10.5),
112+
"ylim": (-10.5, 10.5),
113+
},
114+
"VB01": {
115+
"xlim": (-10.5, 10.5),
116+
"ylim": (-10.5, 10.5),
117+
},
97118
}
98119

99120
OBJECTIVES = {

‎tests/trajectories/_plotters.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,8 +432,8 @@ def __call__(self, ax: plt.Axes) -> None:
432432
ax.set_title(self.title)
433433

434434

435-
class SquareBoxAspectSetter(Plotter):
436-
"""Plotter that sets a square box aspect."""
435+
class BoxAspectSetter(Plotter):
436+
"""Plotter that sets a slightly wider than tall box aspect."""
437437

438438
def __call__(self, ax: plt.Axes) -> None:
439-
ax.set_box_aspect(1)
439+
ax.set_box_aspect(5 / 6)

‎tests/trajectories/plot_distance_to_pf.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
from trajectories._pareto_utils import make_2d_pf_distance_fn
2121
from trajectories._paths import get_distance_to_pf_plots_dir, get_values_dir
2222
from trajectories._plotters import (
23+
BoxAspectSetter,
2324
MultiEvolutionPlotter,
24-
SquareBoxAspectSetter,
2525
TitleSetter,
2626
XAxisLabeller,
2727
XTicksClearer,
@@ -65,7 +65,7 @@ def main() -> None:
6565
objective_key = metadata["objective_key"]
6666
objective = OBJECTIVES[objective_key]
6767

68-
common_plotter = SquareBoxAspectSetter()
68+
common_plotter = BoxAspectSetter()
6969

7070
aggregator_keys = metadata["aggregator_keys"]
7171
aggregator_to_Y = {key: np.load(values_dir / f"{key}.npy") for key in aggregator_keys}

‎tests/trajectories/plot_params.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,22 @@
2222
INITIAL_POINTS,
2323
LATEX_NAMES,
2424
OBJECTIVES,
25+
PLOT_PARAMS_LIMS,
2526
)
2627
from trajectories._objectives import ElementWiseQuadratic, ValleyBowl, WithSPSMappingMixin
2728
from trajectories._optimization import compute_gradient_cosine_similarities
2829
from trajectories._pareto_utils import sample_2d_spss
2930
from trajectories._paths import get_param_plots_dir, get_params_dir
3031
from trajectories._plotters import (
3132
AxesPlotter,
33+
BoxAspectSetter,
3234
ContentLimAdjuster,
3335
ContourCirclesPlotter,
3436
FilledContourPlotter,
3537
HeatmapPlotter,
3638
LimAdjuster,
3739
MultiTrajPlotter,
3840
SPSPlotter,
39-
SquareBoxAspectSetter,
4041
TitleSetter,
4142
XAxisLabeller,
4243
XTicksClearer,
@@ -84,7 +85,7 @@ def main() -> None:
8485
initial_points_array = np.stack([np.array(point) for point in initial_points])
8586
main_content = initial_points_array
8687

87-
common_plotter = SquareBoxAspectSetter()
88+
common_plotter = BoxAspectSetter()
8889

8990
if isinstance(objective, ValleyBowl):
9091
sps_points = objective.pareto_set().numpy()
@@ -101,7 +102,10 @@ def main() -> None:
101102
common_plotter += ContourCirclesPlotter()
102103
common_plotter += LimAdjuster(xlim=(-5.0, 5.0), ylim=(-5.0, 5.0))
103104
else:
104-
adjust_plotter = ContentLimAdjuster(main_content)
105+
if objective_key in PLOT_PARAMS_LIMS:
106+
adjust_plotter = LimAdjuster(**PLOT_PARAMS_LIMS[objective_key])
107+
else:
108+
adjust_plotter = ContentLimAdjuster(main_content)
105109
common_plotter += adjust_plotter
106110

107111
if isinstance(objective, ValleyBowl):
@@ -144,7 +148,7 @@ def main() -> None:
144148
n_aggregators = len(aggregator_keys)
145149
n_rows, n_cols = compute_subplot_layout(n_aggregators)
146150
key_to_index = map_orders_to_indices(aggregator_keys, AGGREGATOR_ORDER)
147-
fig, axes = plt.subplots(n_rows, n_cols, figsize=(n_cols * 2, n_rows * 2.5))
151+
fig, axes = plt.subplots(n_rows, n_cols, figsize=(n_cols * 3, n_rows * 3))
148152
if n_rows == n_cols == 1:
149153
axes = np.array([[axes]])
150154
elif n_rows == 1:

‎tests/trajectories/plot_values.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
from trajectories._pareto_utils import compute_normalized_2d_pf_distances, sample_2d_pf
2828
from trajectories._paths import get_value_plots_dir, get_values_dir
2929
from trajectories._plotters import (
30+
BoxAspectSetter,
3031
ContentLimAdjuster,
3132
FilledContourPlotter,
3233
HeatmapPlotter,
3334
LimAdjuster,
3435
MultiTrajPlotter,
3536
PFPlotter,
36-
SquareBoxAspectSetter,
3737
TitleSetter,
3838
XAxisLabeller,
3939
XTicksClearer,
@@ -77,7 +77,7 @@ def main() -> None:
7777
if objective.n_values != 2:
7878
raise ValueError("Can only plot values trajectories for objectives with 2 values.")
7979

80-
common_plotter = SquareBoxAspectSetter()
80+
common_plotter = BoxAspectSetter()
8181
aggregator_keys = metadata["aggregator_keys"]
8282
aggregator_to_Y = {key: np.load(values_dir / f"{key}.npy") for key in aggregator_keys}
8383
first_agg_Y = next(iter(aggregator_to_Y.values()))
@@ -146,7 +146,7 @@ def main() -> None:
146146
n_aggregators = len(aggregator_keys)
147147
n_rows, n_cols = compute_subplot_layout(n_aggregators)
148148
key_to_index = map_orders_to_indices(aggregator_keys, AGGREGATOR_ORDER)
149-
fig, axes = plt.subplots(n_rows, n_cols, figsize=(n_cols * 2, n_rows * 2.5))
149+
fig, axes = plt.subplots(n_rows, n_cols, figsize=(n_cols * 3, n_rows * 3))
150150
if n_rows == n_cols == 1:
151151
axes = np.array([[axes]])
152152
elif n_rows == 1:

0 commit comments

Comments
 (0)