Skip to content

Commit

Permalink
Fix use of log scales in the case that histograms are being used
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Aug 9, 2024
1 parent 5f30ff1 commit 8d032de
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
16 changes: 12 additions & 4 deletions bin/plotting/pycbc_plot_bank_corner
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ fig, axis_dict = create_multidim_plot(
hist_color=hist_color,
mins=mins,
maxs=maxs,
log_parameters=args.log_parameters,
)

title_text = f"{os.path.basename(args.bank_file)}"
Expand Down Expand Up @@ -322,10 +323,17 @@ for i in range(len(args.parameters)):
s0.sharex(s1)

for (p1, p2), ax in axis_dict.items():
if p1 in args.log_parameters:
ax[0].semilogx()
if p2 in args.log_parameters:
ax[0].semilogy()
if p1 == p2:
if p1 == args.parameters[-1] and len(args.parameters) == 2:
# This will be turned on its side, so set _y_ axis to log
ax[0].semilogy()
else:
ax[0].semilogx()
else:
if p1 in args.log_parameters:
ax[0].semilogx()
if p2 in args.log_parameters:
ax[0].semilogy()

logging.info("Plot generated")
fig.set_dpi(args.dpi)
Expand Down
23 changes: 20 additions & 3 deletions pycbc/results/scatter_histograms.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def create_marginalized_hist(ax, values, label, percentiles=None,
linestyle='-', plot_marginal_lines=True,
title=True, expected_value=None,
expected_color='red', rotated=False,
plot_min=None, plot_max=None):
plot_min=None, plot_max=None, log_scale=False):
"""Plots a 1D marginalized histogram of the given param from the given
samples.
Expand Down Expand Up @@ -380,6 +380,8 @@ def create_marginalized_hist(ax, values, label, percentiles=None,
creates.
scalefac : {1., float}
Factor to scale the default font sizes by. Default is 1 (no scaling).
log_scale : boolean
Should the histogram bins be logarithmically spaced
"""
if fillcolor is None:
htype = 'step'
Expand All @@ -389,7 +391,19 @@ def create_marginalized_hist(ax, values, label, percentiles=None,
orientation = 'horizontal'
else:
orientation = 'vertical'
ax.hist(values, bins=50, histtype=htype, orientation=orientation,
if log_scale:
bins = numpy.logspace(
numpy.log10(numpy.nanmin(values)),
numpy.log10(numpy.nanmax(values)),
50
)
else:
bins = numpy.linspace(
numpy.nanmin(values),
numpy.nanmax(values),
50,
)
ax.hist(values, bins=bins, histtype=htype, orientation=orientation,
facecolor=fillcolor, edgecolor=color, ls=linestyle, lw=2,
density=True)
if percentiles is None:
Expand Down Expand Up @@ -545,7 +559,7 @@ def create_multidim_plot(parameters, samples, labels=None,
marginal_title=True, marginal_linestyle='-',
zvals=None, show_colorbar=True, cbar_label=None,
vmin=None, vmax=None, scatter_cmap='plasma',
scatter_log_cmap=False,
scatter_log_cmap=False, log_parameters=None,
plot_density=False, plot_contours=True,
density_cmap='viridis',
contour_color=None, label_contours=True,
Expand Down Expand Up @@ -640,6 +654,8 @@ def create_multidim_plot(parameters, samples, labels=None,
Use the given figure instead of creating one.
axis_dict : dict
Use the given dictionary of axes instead of creating one.
log_parameters : list
Which parameters should be plotted on a log scale
Returns
-------
Expand Down Expand Up @@ -735,6 +751,7 @@ def create_multidim_plot(parameters, samples, labels=None,
create_marginalized_hist(
ax, samples[param], label=labels[param],
color=hist_color, fillcolor=fill_color,
log_scale=param in log_parameters,
plot_marginal_lines=plot_marginal_lines,
linestyle=marginal_linestyle, linecolor=line_color,
title=marginal_title, expected_value=expected_value,
Expand Down

0 comments on commit 8d032de

Please sign in to comment.