Skip to content

Commit

Permalink
[plot] Optional plot titles
Browse files Browse the repository at this point in the history
  • Loading branch information
stephane-caron authored and Stéphane Caron committed Mar 15, 2023
1 parent 127ca3e commit 4b417e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
13 changes: 9 additions & 4 deletions benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ def parse_command_line_arguments():
"settings",
help='settings to compare solvers on (e.g. "high_accuracy")',
)
parser_plot.add_argument(
"--linewidth",
help="width of plotted lines in px",
type=int,
default=3,
)
parser_plot.add_argument(
"--savefig",
help="path to a file to save the plot to (rather than displaying it)",
Expand All @@ -105,10 +111,8 @@ def parse_command_line_arguments():
nargs="+",
)
parser_plot.add_argument(
"--linewidth",
help="width of plotted lines in px",
type=int,
default=3,
"--title",
help='plot title (set to "" to disable)',
)

# report
Expand Down Expand Up @@ -250,6 +254,7 @@ def load_test_set(name: str) -> TestSet:
solvers=args.solvers,
linewidth=args.linewidth,
savefig=args.savefig,
title=args.title,
)

if args.command in ["report", "run"]:
Expand Down
11 changes: 8 additions & 3 deletions qpsolvers_benchmark/plot_metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def plot_metric(
solvers: Optional[List[str]] = None,
linewidth: float = 3.0,
savefig: Optional[str] = None,
title: Optional[str] = None,
) -> None:
"""Plot comparing solvers on a given metric.
Expand All @@ -45,6 +46,7 @@ def plot_metric(
solvers: Names of solvers to compare (default: all).
linewidth: Width of output lines, in px.
savefig: If set, save plot to this path rather than displaying it.
title: Plot title, set to "" to disable.
"""
assert issubclass(df[metric].dtype.type, np.floating)
nb_problems = test_set.count_problems()
Expand All @@ -68,9 +70,12 @@ def plot_metric(
padded_y = np.hstack([y, [nb_solved]])
plt.step(padded_values, padded_y, linewidth=linewidth)
plt.legend(plot_solvers)
plt.title(
f"Comparing {metric} on {test_set.title} with {settings} settings"
)
if title is None:
plt.title(
f"Comparing {metric} on {test_set.title} with {settings} settings"
)
elif title != "":
plt.title(title)
plt.xlabel(metric)
plt.xscale("log")
plt.axhline(y=nb_problems, color="gray", linestyle=":")
Expand Down

0 comments on commit 4b417e8

Please sign in to comment.