Skip to content

Commit 468f3a2

Browse files
committed
Merge branch 'dev' of https://github.com/bayesflow-org/bayesflow into dev
2 parents f147929 + 99a866f commit 468f3a2

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

bayesflow/diagnostics/plots/pairs_samples.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import pandas as pd
55
import seaborn as sns
66

7+
import matplotlib.pyplot as plt
8+
79
from bayesflow.utils import logging
810
from bayesflow.utils.dict_utils import dicts_to_arrays
911

@@ -122,7 +124,7 @@ def _pairs_samples(
122124

123125
# add histograms + KDEs to the diagonal
124126
g.map_diag(
125-
sns.histplot,
127+
histplot_twinx,
126128
fill=True,
127129
kde=True,
128130
color=color,
@@ -169,3 +171,23 @@ def _pairs_samples(
169171
g.tight_layout()
170172

171173
return g
174+
175+
176+
# create a histogram plot on a twin y axis
177+
# this ensures that the y scaling of the diagonal plots
178+
# in independent of the y scaling of the off-diagonal plots
179+
def histplot_twinx(x, **kwargs):
180+
# Create a twin axis
181+
ax2 = plt.gca().twinx()
182+
183+
# create a histogram on the twin axis
184+
sns.histplot(x, **kwargs, ax=ax2)
185+
186+
# make the twin axis invisible
187+
plt.gca().spines["right"].set_visible(False)
188+
plt.gca().spines["top"].set_visible(False)
189+
ax2.set_ylabel("")
190+
ax2.set_yticks([])
191+
ax2.set_yticklabels([])
192+
193+
return None

0 commit comments

Comments
 (0)