<commit_before>import os
import numpy as np
import pandas as pd
import scipy
from pandas.api.types import is_categorical_dtype
import networkx as nx
from matplotlib import pyplot as pl
from matplotlib.colors import is_color_like
from matplotlib import rcParams, ticker
from collections import Iterable

from .. import utils
from ... import utils as sc_utils
from ... import settings
from ... import logging as logg
from ..utils import matrix


def paga_compare(
        adata,
        basis=None,
        edges=None,
        color=None,
        alpha=None,
        groups=None,
        components=None,
        projection='2d',
        legend_loc='on data',
        legend_fontsize=None,
        legend_fontweight=None,
        color_map=None,
        palette=None,
        size=None,
        title=None,
        right_margin=None,
        left_margin=0.05,
        show=None,
        save=None,
        title_graph=None,
        groups_graph=None,
        **paga_graph_params):
    """Scatter and PAGA graph side-by-side.

    Consists in a scatter plot and the abstracted graph. See
    :func:`~scanpy.api.pl.paga` for all related parameters.

    See :func:`~scanpy.api.pl.paga_path` for visualizing gene changes along paths
    through the abstracted graph.

    Additional parameters are as follows.

    Parameters
    ----------
    adata : :class:`~anndata.AnnData`
        Annotated data matrix.
    kwds_scatter : `dict`
        Keywords for :func:`~scanpy.api.pl.scatter`.
    kwds_paga : `dict`
        Keywords for :func:`~scanpy.api.pl.paga`.
    """
    axs, _, _, _ = utils.setup_axes(panels=[0, 1],
                                    right_margin=right_margin)  # dummy colors
    # set a common title for the figure
    suptitle = None
    if title is not None and title_graph is None:
        suptitle = title
        title = ''
        title_graph = ''
    if basis is None:
        if 'X_draw_graph_fa' in adata.obsm.keys():
            basis = 'draw_graph_fa'
        elif 'X_umap' in adata.obsm.keys():
            basis = 'umap'
        elif 'X_tsne' in adata.obsm.keys():
            basis = 'tsne'
        elif 'X_draw_graph_fr' in adata.obsm.keys():
            basis = 'draw_graph_fr'
        else:
            basis = 'umap'
    _paga_scatter(
        adata,
        basis=basis,
        edges=edges,
        color=color,
        alpha=alpha,
        groups=groups,
        components=components,
        projection=projection,
        legend_loc=legend_loc,
        legend_fontsize=legend_fontsize,
        legend_fontweight=legend_fontweight,
        color_map=color_map,
        palette=palette,
        right_margin=None,
        size=size,
        title=title,
        ax=axs[0],
        show=False,
        save=False)
    if 'pos' not in paga_graph_params:
        paga_graph_params['pos'] = utils._tmp_cluster_pos
    paga(adata, ax=axs[1], show=False, save=False, title=title_graph,
         labels=groups_graph, colors=color, **paga_graph_params)
    if suptitle is not None: pl.suptitle(suptitle)
    utils.savefig_or_show('paga_compare', show=show, save=save)
    if show == False: return axs


def _paga_scatter(
        adata,
        basis='tsne',
        edges=None,
        color=None,
        alpha=None,
        groups=None,
        components=None,
        projection='2d',
        legend_loc='right margin',
        legend_fontsize=None,
        legend_fontweight=None,
        color_map=None,
        palette=None,
        size=None,
        title=None,
        right_margin=None,
        show=None,
        save=None,
        ax=None):
    if color is None:
        color = [adata.uns['paga']['groups']]
    if not isinstance(color, list): color = [color]
    kwds = {}
    if 'draw_graph' in basis:
        from . import draw_graph
        scatter_func = draw_graph
        kwds['edges'] = True if edges is None else edges
    elif basis == 'umap':
        from . import umap
        scatter_func = umap
        kwds['edges'] = True if edges is None else edges
    else:
        from . import scatter
        scatter_func = scatter
        kwds['basis'] = basis
    axs = scatter_func(
        adata,
        color=color,
        alpha=alpha,
        groups=groups,
        components=components,
        legend_loc=legend_loc,
        legend_fontsize=legend_fontsize,
        legend_fontweight=legend_fontweight,
        color_map=color_map,
        palette=palette,
        right_margin=right_margin,
        size=size,
        title=title,
        ax=ax,
        show=False,
        **kwds)
    utils.savefig_or_show('paga_' + basis, show=show, save=save)
    if show == False: return axs<commit_msg>fixed bug in paga plotting<commit_after>import os
import numpy as np
import pandas as pd
import scipy
from pandas.api.types import is_categorical_dtype
import networkx as nx
from matplotlib import pyplot as pl
from matplotlib.colors import is_color_like
from matplotlib import rcParams, ticker
from collections import Iterable

from .. import utils
from ... import utils as sc_utils
from ... import settings
from ... import logging as logg
from ..utils import matrix


def paga_compare(
        adata,
        basis=None,
        edges=None,
        color=None,
        alpha=None,
        groups=None,
        components=None,
        projection='2d',
        legend_loc='on data',
        legend_fontsize=None,
        legend_fontweight=None,
        color_map=None,
        palette=None,
        size=None,
        title=None,
        right_margin=None,
        left_margin=0.05,
        show=None,
        save=None,
        title_graph=None,
        groups_graph=None,
        **paga_graph_params):
    """Scatter and PAGA graph side-by-side.

    Consists in a scatter plot and the abstracted graph. See
    :func:`~scanpy.api.pl.paga` for all related parameters.

    See :func:`~scanpy.api.pl.paga_path` for visualizing gene changes along paths
    through the abstracted graph.

    Additional parameters are as follows.

    Parameters
    ----------
    adata : :class:`~anndata.AnnData`
        Annotated data matrix.
    kwds_scatter : `dict`
        Keywords for :func:`~scanpy.api.pl.scatter`.
    kwds_paga : `dict`
        Keywords for :func:`~scanpy.api.pl.paga`.
    """
    axs, _, _, _ = utils.setup_axes(panels=[0, 1],
                                    right_margin=right_margin)  # dummy colors
    # set a common title for the figure
    suptitle = None
    if title is not None and title_graph is None:
        suptitle = title
        title = ''
        title_graph = ''
    if basis is None:
        if 'X_draw_graph_fa' in adata.obsm.keys():
            basis = 'draw_graph_fa'
        elif 'X_umap' in adata.obsm.keys():
            basis = 'umap'
        elif 'X_tsne' in adata.obsm.keys():
            basis = 'tsne'
        elif 'X_draw_graph_fr' in adata.obsm.keys():
            basis = 'draw_graph_fr'
        else:
            basis = 'umap'
    _paga_scatter(
        adata,
        basis=basis,
        edges=edges,
        color=color,
        alpha=alpha,
        groups=groups,
        components=components,
        projection=projection,
        legend_loc=legend_loc,
        legend_fontsize=legend_fontsize,
        legend_fontweight=legend_fontweight,
        color_map=color_map,
        palette=palette,
        right_margin=None,
        size=size,
        title=title,
        ax=axs[0],
        show=False,
        save=False)
    if 'pos' not in paga_graph_params:
        paga_graph_params['pos'] = utils._tmp_cluster_pos
    paga(adata, ax=axs[1], show=False, save=False, title=title_graph,
         labels=groups_graph, colors=color, **paga_graph_params)
    if suptitle is not None: pl.suptitle(suptitle)
    utils.savefig_or_show('paga_compare', show=show, save=save)
    if show == False: return axs


def _paga_scatter(
        adata,
        basis='tsne',
        edges=None,
        color=None,
        alpha=None,
        groups=None,
        components=None,
        projection='2d',
        legend_loc='right margin',
        legend_fontsize=None,
        legend_fontweight=None,
        color_map=None,
        palette=None,
        size=None,
        title=None,
        right_margin=None,
        show=None,
        save=None,
        ax=None):
    if color is None:
        color = [adata.uns['paga']['groups']]
    if not isinstance(color, list): color = [color]
    kwds = {}
    if 'draw_graph' in basis:
        from .embedding import draw_graph
        scatter_func = draw_graph
        kwds['edges'] = True if edges is None else edges
    elif basis == 'umap':
        from .embedding import umap
        scatter_func = umap
        kwds['edges'] = True if edges is None else edges
    else:
        from ..anndata import scatter
        scatter_func = scatter
        kwds['basis'] = basis
    axs = scatter_func(
        adata,
        color=color,
        alpha=alpha,
        groups=groups,
        components=components,
        legend_loc=legend_loc,
        legend_fontsize=legend_fontsize,
        legend_fontweight=legend_fontweight,
        color_map=color_map,
        palette=palette,
        right_margin=right_margin,
        size=size,
        title=title,
        ax=ax,
        show=False,
        **kwds)
    utils.savefig_or_show('paga_' + basis, show=show, save=save)
    if show == False: return axs
{'fraction_non_alphanumeric': 0.09419437613599914, 'fraction_numerical': 0.0019245161980113333, 'mean_word_length': 2.1410342511752853, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5911885', 'n_tokens_mistral': 2930, 'n_tokens_neox': 2897, 'n_words': 702}