Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance legend setting in pycbc_inference_plot_posterior #4964

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 16 additions & 1 deletion bin/inference/pycbc_inference_plot_posterior
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ parser.add_argument("--plot-maxl", action="store_true", default=False,
parser.add_argument('--legend-location', default='upper right',
help='Where to put the legend (if multiple files are '
'provided). Default is "upper right".')
parser.add_argument('--legend-bbox-to-anchor', default='(1.0, 1.0)',
help='Box that is used to position the legend in conjunction with loc.')
parser.add_argument('--legend-fontsize', default='medium',
help="The font size of legend. Default is 'medium'."
"Choose from int or {'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}.")
parser.add_argument('--dpi', type=int, default=200,
help="Set the DPI of the plot. Default is 200.")
# style option
Expand Down Expand Up @@ -114,6 +119,15 @@ if opts.plot_maxl:
else:
add_logl = False

# parse legend bbox
def parse_tuple(value):
try:
return tuple(map(float, value.strip("()").split(",")))
except Exception as e:
raise argparse.ArgumentTypeError(f"Invalid tuple format: {value}") from e

opts.legend_bbox_to_anchor = parse_tuple(opts.legend_bbox_to_anchor)

# set logging
pycbc.init_logging(opts.verbose)

Expand Down Expand Up @@ -359,7 +373,8 @@ if len(opts.input_file) > 1:
else:
addto = fig
addto.legend(loc=opts.legend_location, handles=handles,
labels=labels)
labels=labels, fontsize=opts.legend_fontsize,
bbox_to_anchor=opts.legend_bbox_to_anchor)

# set DPI
fig.set_dpi(opts.dpi)
Expand Down
Loading