Skip to content
Merged
Show file tree
Hide file tree
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
52 changes: 33 additions & 19 deletions scanpy/plotting/_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -731,35 +731,49 @@ def violin(
x = groupby
ys = keys

# set by default the violin plot cut=0 to limit the extend
# of the violin plot (see stacked_violin code) for more info.
kwds.setdefault('cut', 0)
kwds.setdefault('inner')

if multi_panel and groupby is None and len(ys) == 1:
# This is a quick and dirty way for adapting scales across several
# keys if groupby is None.
y = ys[0]
g = sns.FacetGrid(obs_tidy, col=x, col_order=keys, sharey=False)
# don't really know why this gives a warning without passing `order`
g = g.map(sns.violinplot, y, orient='vertical', scale=scale, order=keys, **kwds)

g = sns.catplot(
y=y,
data=obs_tidy,
kind="violin",
scale=scale,
col=x,
col_order=keys,
sharey=False,
order=keys,
cut=0,
inner=None,
**kwds,
)

if stripplot:
g = g.map(
sns.stripplot,
y,
orient='vertical',
jitter=jitter,
size=size,
order=keys,
color='black',
)
grouped_df = obs_tidy.groupby(x)
for ax_id, key in zip(range(g.axes.shape[1]), keys):
sns.stripplot(
y=y,
data=grouped_df.get_group(key),
jitter=jitter,
size=size,
color="black",
ax=g.axes[0, ax_id],
**kwds,
)
if log:
g.set(yscale='log')
g.set_titles(col_template='{col_name}').set_xlabels('')
if rotation is not None:
for ax in g.axes[0]:
ax.tick_params(axis='x', labelrotation=rotation)
else:
# set by default the violin plot cut=0 to limit the extend
# of the violin plot (see stacked_violin code) for more info.
kwds.setdefault('cut', 0)
kwds.setdefault('inner')

if ax is None:
axs, _, _, _ = setup_axes(
ax=ax,
Expand All @@ -771,7 +785,7 @@ def violin(
axs = [ax]
for ax, y, ylab in zip(axs, ys, ylabel):
ax = sns.violinplot(
x,
x=x,
y=y,
data=obs_tidy,
order=order,
Expand All @@ -782,7 +796,7 @@ def violin(
)
if stripplot:
ax = sns.stripplot(
x,
x=x,
y=y,
data=obs_tidy,
order=order,
Expand Down
Binary file modified scanpy/tests/_images/master_violin_multi_panel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/notebooks/pbmc3k_images/violin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.