Skip to content

Commit 5e862c0

Browse files
committed
better direct calculation histograms
1 parent 662e879 commit 5e862c0

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

RATapi/examples/bayes_benchmark/bayes_benchmark.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def plot_posterior_comparison(ns_results: RAT.outputs.BayesResults, calc_results
188188
num_params = calc_results.distribution.ndim
189189
fig, axes = plt.subplots(2, num_params)
190190

191-
def plot_marginalised_result(dimension: int, axes: plt.Axes):
191+
def plot_marginalised_result(dimension: int, axes: plt.Axes, limits: tuple[float]):
192192
"""Plot a histogram of a marginalised posterior from the calculation results.
193193
194194
Parameters
@@ -197,6 +197,8 @@ def plot_marginalised_result(dimension: int, axes: plt.Axes):
197197
The dimension of the array to marginalise over.
198198
axes : plt.Axes
199199
The Axes object to plot the histogram onto.
200+
limits : tuple[float]
201+
The x-axis limits for the histogram.
200202
201203
"""
202204
# marginalise to the dimension
@@ -207,9 +209,10 @@ def plot_marginalised_result(dimension: int, axes: plt.Axes):
207209
# create histogram
208210
axes.hist(
209211
calc_results.x_data[i],
212+
bins=25,
213+
range=limits,
210214
weights=distribution,
211215
density=True,
212-
bins=25,
213216
edgecolor="black",
214217
linewidth=1.2,
215218
color="white",
@@ -219,8 +222,7 @@ def plot_marginalised_result(dimension: int, axes: plt.Axes):
219222
# row 1 contains direct calculation histograms for each parameter
220223
for i in range(0, num_params):
221224
RATplot.plot_one_hist(ns_results, i, smooth=False, axes=axes[0][i])
222-
plot_marginalised_result(i, axes[1][i])
223-
axes[1][i].set_xlim(*axes[0][i].get_xlim())
225+
plot_marginalised_result(i, axes[1][i], limits=axes[0][i].get_xlim())
224226

225227
axes[0][0].set_ylabel("nested sampler")
226228
axes[1][0].set_ylabel("direct calculation")
@@ -234,5 +236,5 @@ def plot_marginalised_result(dimension: int, axes: plt.Axes):
234236
ns_3d, calc_3d = bayes_benchmark_3d(40)
235237

236238
plot_posterior_comparison(ns_2d, calc_2d)
237-
239+
238240
plot_posterior_comparison(ns_3d, calc_3d)

0 commit comments

Comments
 (0)