Skip to content

Commit

Permalink
Merge pull request scverse#776 from theislab/violin-multipanel-fix
Browse files Browse the repository at this point in the history
Fix sc.pl.violin not making violinplots
  • Loading branch information
fidelram authored Aug 30, 2019
2 parents 6099cd3 + df91a72 commit d901c96
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
38 changes: 18 additions & 20 deletions scanpy/plotting/_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,25 +673,23 @@ def violin(
obs_tidy = obs_df
x = groupby
ys = keys
if multi_panel:
if 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, inner=None, orient='vertical',
scale=scale, order=keys, **kwds)
if stripplot:
g = g.map(sns.stripplot, y, orient='vertical', jitter=jitter, size=size, order=keys,
color='black')
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(labelrotation=rotation)

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, inner=None, orient='vertical',
scale=scale, order=keys, **kwds)
if stripplot:
g = g.map(sns.stripplot, y, orient='vertical', jitter=jitter, size=size, order=keys,
color='black')
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(labelrotation=rotation)
else:
if ax is None:
axs, _, _, _ = setup_axes(
Expand All @@ -713,7 +711,7 @@ def violin(
ax.tick_params(labelrotation=rotation)
utils.savefig_or_show('violin', show=show, save=save)
if show is False:
if multi_panel:
if multi_panel and groupby is None and len(ys) == 1:
return g
elif len(axs) == 1:
return axs[0]
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions scanpy/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def test_violin(image_comparer):
stripplot=True, multi_panel=True, jitter=True, show=False)
save_and_compare_images('master_violin_multi_panel')

sc.pl.violin(pbmc, ['n_genes', 'percent_mito', 'n_counts'], groupby='bulk_labels',
stripplot=True, multi_panel=True, jitter=True, show=False)
save_and_compare_images('master_violin_multi_panel_with_groupby')


def test_dendrogram(image_comparer):
save_and_compare_images = image_comparer(ROOT, FIGS, tol=10)
Expand Down

0 comments on commit d901c96

Please sign in to comment.