def _rank_genes_groups_plot(adata, plot_type='heatmap', groups=None,
                            n_genes=10, groupby=None, key=None,
                            show=None, save=None, **kwds):
    """\
    Plot ranking of genes using the specified plot type

    Parameters
    ----------
    adata : :class:`~anndata.AnnData`
        Annotated data matrix.
    groups : `str` or `list` of `str`
        The groups for which to show the gene ranking.
    n_genes : `int`, optional (default: 10)
        Number of genes to show.
    groupby : `str` or `None`, optional (default: `None`)
        The key of the observation grouping to consider. By default,
        the groupby is chosen from the rank genes groups parameter but
        other groupby options can be used.
    {show_save_ax}
    """
    if key is None:
        key = 'rank_genes_groups'

    if 'dendrogram' not in kwds:
        kwds['dendrogram'] = True
    if groupby is None:
        groupby = str(adata.uns[key]['params']['groupby'])
    group_names = (adata.uns[key]['names'].dtype.names
                   if groups is None else groups)

    gene_names = []
    start = 0
    group_positions = []
    group_names_valid = []
    for group in group_names:
        # get all genes that are 'not-nan'
        genes_list = [gene for gene in adata.uns[key]['names'][group] if not pd.isnull(gene)][:n_genes]
        if len(genes_list) == 0:
            logg.warn("No genes found for group {}".format(group))
            continue
        gene_names.extend(genes_list)
        end = start + len(genes_list)
        group_positions.append((start, end -1))
        group_names_valid.append(group)
        start = end

    group_names = group_names_valid
    if plot_type == 'dotplot':
        from .._anndata import dotplot
        dotplot(adata, gene_names, groupby, var_group_labels=group_names,
                var_group_positions=group_positions, show=show, save=save, **kwds)

    elif plot_type == 'heatmap':
        from .._anndata import heatmap
        heatmap(adata, gene_names, groupby, var_group_labels=group_names,
                var_group_positions=group_positions, show=show, save=save, **kwds)

    elif plot_type == 'stacked_violin':
        from .._anndata import stacked_violin
        return stacked_violin(adata, gene_names, groupby, var_group_labels=group_names,
                       var_group_positions=group_positions, show=show, save=save, **kwds)

    elif plot_type == 'tracksplot':
        from .._anndata import tracksplot
        return tracksplot(adata, gene_names, groupby, var_group_labels=group_names,
                       var_group_positions=group_positions, show=show, save=save, **kwds)

    elif plot_type == 'matrixplot':
        from .._anndata import matrixplot
        matrixplot(adata, gene_names, groupby, var_group_labels=group_names,
                   var_group_positions=group_positions, show=show, save=save, **kwds)
\
    Plot ranking of genes using the specified plot type

    Parameters
    ----------
    adata : :class:`~anndata.AnnData`
        Annotated data matrix.
    groups : `str` or `list` of `str`
        The groups for which to show the gene ranking.
    n_genes : `int`, optional (default: 10)
        Number of genes to show.
    groupby : `str` or `None`, optional (default: `None`)
        The key of the observation grouping to consider. By default,
        the groupby is chosen from the rank genes groups parameter but
        other groupby options can be used.
    {show_save_ax}