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

Enable setting zorder of each bivariate distribution in kernel density plots #207

Merged
merged 1 commit into from
Oct 31, 2024
Merged
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
7 changes: 4 additions & 3 deletions biosteam/plots/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ def plot_kde(x, y, nbins=100, ax=None, fig=None,
xtick0=True, ytick0=True, xtickf=True, ytickf=True,
xbox=None, ybox=None, xbox_kwargs=None, ybox_kwargs=None,
aspect_ratio=1.25, cmaps=None, xbox_width=None,
ybox_width=None, **kwargs):
ybox_width=None, zorders=None, **kwargs):
axis_not_given = ax is None
xs = x if isinstance(x, (tuple, list)) else (x,)
ys = y if isinstance(y, (tuple, list)) else (y,)
Expand Down Expand Up @@ -892,7 +892,8 @@ def plot_kde(x, y, nbins=100, ax=None, fig=None,
else:
yboxes = ybox
if cmaps is None: cmaps = len(xs) * [None]
for x, y, cmap, xbox, ybox in zip(xs, ys, cmaps, xboxes, yboxes):
if zorders is None: zorders = len(xs) * [5]
for x, y, cmap, zorder, xbox, ybox in zip(xs, ys, cmaps, zorders, xboxes, yboxes):
# Evaluate a gaussian kde on a regular grid of nbins x nbins over data extents
k = kde.gaussian_kde([x, y])
z = k(np.vstack([x, y]))
Expand All @@ -906,7 +907,7 @@ def plot_kde(x, y, nbins=100, ax=None, fig=None,
# 2D Density with shading
plt.sca(ax)

plt.scatter(x, y, c=z, s=1., cmap=cmap, **kwargs)
plt.scatter(x, y, c=z, s=1., cmap=cmap, zorder=zorder, **kwargs)
if xbox:
plt.sca(xbox.axis)
plot_montecarlo(x, xbox.light, xbox.dark, positions=(xbox.get_position(-1),), vertical=False, outliers=False, width=xbox_width, bounds=True)
Expand Down
Loading