fig = plt.figure(figsize=(15, 25))
outer_grid = fig.add_gridspec(4, 2, hspace=0.4, wspace=0.3)
for adata in datasets:
i = location[adata.uns['name']]
grid_box = outer_grid[i]
inner_grid = grid_box.subgridspec(2, 2)
# -- Global --
ax = fig.add_subplot(inner_grid[0])
ax.set_title('Global dispersion')
ax.set_xscale('log')
ax.set_xlim(left=2e-4, right=1e5)
ax.scatter(adata.var['empirical_mean'],
adata.var['empirical_zero_fraction'],
c='k', label='Observed', rasterized=True);
ax.scatter(adata.var['empirical_mean'],
adata.var['global_zero_fraction'],
ec='w', c='grey', label='Expected', rasterized=True);
ax.set_ylabel('Fraction zeros')
ax.legend(title='Genes', loc='lower left', scatterpoints=3, fontsize=8)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
## _
ax = fig.add_subplot(inner_grid[2])
ax.set_xscale('log')
ax.set_xlim(left=2e-4, right=1e5)
ax.set_ylim(top=0.7, bottom=-0.7)
difference = adata.var['empirical_zero_fraction'] - adata.var['global_zero_fraction']
ax.scatter(adata.var['empirical_mean'],
difference,
c='k', marker='.', label='Genes', rasterized=True)
ax.set_ylabel('Difference \n(Observed - Expected)')
ax.set_xlabel('Mean')
ax.legend(loc='lower left', scatterpoints=3)
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
# -- Genewise --
ax = fig.add_subplot(inner_grid[1])
ax.set_title('Genewise dispersion')
ax.set_xscale('log')
ax.set_xlim(left=2e-4, right=1e5)
ax.scatter(adata.var['empirical_mean'],
adata.var['empirical_zero_fraction'],
c='k', rasterized=True);
ax.scatter(adata.var['empirical_mean'],
adata.var['genewise_zero_fraction'],
ec='w', c='grey', rasterized=True);
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
## _
ax = fig.add_subplot(inner_grid[3])
ax.set_xscale('log')
ax.set_xlim(left=2e-4, right=1e5)
ax.set_ylim(top=0.7, bottom=-0.7)
difference = adata.var['empirical_zero_fraction'] - adata.var['genewise_zero_fraction']
ax.scatter(adata.var['empirical_mean'],
difference,
c='k', marker='.', rasterized=True)
ax.set_xlabel('Mean')
ax.spines['top'].set_visible(False)
ax.spines['right'].set_visible(False)
# -- Annotation --
bbox = grid_box.get_position(fig)
x = (bbox.x0 + bbox.x1) / 2
y = bbox.y1 + 0.015
fig.text(x, y, adata.uns['name'] + '\n' + annotation[adata.uns['name']], ha='center', fontsize=12)
fig.savefig('../Figures/smarter_nb_plot.pdf', dpi=500, bbox_inches='tight')