0

I'm working on analyzing some data using scanpy and I'm trying to plot 3 violin plots next to one another but I can't seem to get it to work. I tried using subplots a few different ways but they keep getting empty charts with the violin plots in between them. I tried a few different strategies but I can't seem to get them next to one another in a 1x3 grid. Below is my latest attempt along with part of the plot showing an empty plot stacked on top of a violin plot.

plt.figure()
plt.subplot(1,3,1)
sc.pl.violin(visium, keys = 'n_genes_by_counts')
plt.subplot(1,3,2)
sc.pl.violin(visium, keys = 'total_counts')
plt.subplot(1,3,3)
sc.pl.violin(visium, keys = 'pct_counts_mt')

Sample

enter image description here

Subbu VidyaSekar
  • 2,503
  • 3
  • 21
  • 39
Brian M.
  • 1
  • 1

2 Answers2

2

Try to set multi_panel = True

like this:

sc.pl.violin(visium, ['n_genes_by_counts','total_counts','pct_counts_mt'],
             jitter=0.3, multi_panel=True)
Osadhi Virochana
  • 1,294
  • 2
  • 11
  • 21
0

Either use the flag multi_panel = True in sc.pl.violin, or the ax flag:

plt.figure()
ax1 = plt.subplot(1,3,1)
sc.pl.violin(visium, keys = 'n_genes_by_counts', ax = ax1)
ax2 = plt.subplot(1,3,2)
sc.pl.violin(visium, keys = 'total_counts', ax = ax2)
ax3 = plt.subplot(1,3,3)
sc.pl.violin(visium, keys = 'pct_counts_mt', ax = ax3)