Skip to content

Commit

Permalink
Add '--dpi' option to sinter plot (#827)
Browse files Browse the repository at this point in the history
  • Loading branch information
Strilanc authored Sep 15, 2024
1 parent 36cb178 commit c5830cd
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions glue/sample/src/sinter/_command/_main_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ def parse_args(args: List[str]) -> Any:
nargs=2,
default=None,
help='Desired figure width and height in pixels.')
parser.add_argument('--dpi',
type=float,
default=100,
help='Dots per inch. Determines resolution of the figure.')
parser.add_argument('--group_func',
type=str,
default="'all data (use -group_func and -x_func to group into curves)'",
Expand Down Expand Up @@ -551,6 +555,7 @@ def _plot_helper(
plot_args_func: Callable[[int, Any, List['sinter.TaskStats']], Dict[str, Any]],
line_fits: bool,
point_label_func: Callable[['sinter.TaskStats'], Any] = lambda _: None,
dpi: float,
) -> Tuple[plt.Figure, List[plt.Axes]]:
if isinstance(samples, ExistingData):
total = samples
Expand Down Expand Up @@ -733,12 +738,12 @@ def stat_to_err_rate(stat: 'sinter.TaskStats') -> Optional[float]:
ax.set_title(ax.title.get_text() + '\n' + subtitle)

if fig_size is None:
fig.set_size_inches(10 * num_plots, 10)
fig.set_dpi(100)
fig.set_dpi(dpi)
fig.set_size_inches(1000 * num_plots / dpi, 1000 / dpi)
else:
w, h = fig_size
fig.set_size_inches(w / 100, h / 100)
fig.set_dpi(100)
fig.set_dpi(dpi)
fig.set_size_inches(w / dpi, h / dpi)
fig.tight_layout()
axs = [e for e in [ax_err, ax_dis] if e is not None]
return fig, axs
Expand Down Expand Up @@ -804,8 +809,9 @@ def main_plot(*, command_line_args: List[str]):
subtitle=args.subtitle,
line_fits=args.line_fits,
preprocess_stats_func=args.preprocess_stats_func,
dpi=args.dpi,
)
if args.out is not None:
fig.savefig(args.out)
fig.savefig(args.out, dpi=args.dpi)
if args.show or args.out is None:
plt.show()

0 comments on commit c5830cd

Please sign in to comment.