コード例 #1
0
def get_colors(adata, c):
    if is_color_like(c):
        return c
    else:
        if c+'_colors' not in adata.uns.keys():
            palette = default_palette(None)
            palette = adjust_palette(palette, length=len(adata.obs[c].cat.categories))
            adata.uns[c + '_colors'] = palette[:len(adata.obs[c].cat.categories)].by_key()['color']
        cluster_ix = adata.obs[c].cat.codes
        return np.array([adata.uns[c + '_colors'][cluster_ix[i]] for i in range(adata.n_obs)])
コード例 #2
0
ファイル: utils.py プロジェクト: ahy1221/scvelo
def hist(arrays,
         alpha=.5,
         bins=None,
         colors=None,
         labels=None,
         xlabel=None,
         ylabel=None,
         ax=None,
         figsize=None,
         dpi=None):
    ax = pl.figure(None, figsize, dpi=dpi) if ax is None else ax
    arrays = arrays if isinstance(arrays, (list, tuple)) else [arrays]

    palette = default_palette(None)[::3][:len(arrays)].by_key()['color']
    colors = palette if colors is None or len(colors) < len(arrays) else colors

    for i, array in enumerate(arrays):
        pl.hist(array[np.isfinite(array)],
                bins=bins,
                alpha=alpha,
                color=colors[i],
                label=labels[i] if labels is not None else None)
    pl.legend()
    pl.xlabel(xlabel if xlabel is not None else '')
    pl.ylabel(ylabel if xlabel is not None else '')
    pl.show()


# def phase(adata, var=None, x=None, y=None, color='louvain', fits='all', xlabel='spliced', ylabel='unspliced',
#           fontsize=None, show=True, ax=None, **kwargs):
#     if isinstance(var, str) and (var in adata.var_names):
#         if (x is None) or (y is None):
#             ix = np.where(adata.var_names == var)[0][0]
#             x, y = adata.layers['Ms'][:, ix], adata.layers['Mu'][:, ix]
#     else:
#         ValueError('var not found in adata.var_names.')
#
#     ax = scatter(adata, x=x, y=y, color=color, frameon=True, title=var, xlabel=xlabel, ylabel=ylabel, ax=ax, **kwargs)
#
#     xnew = np.linspace(0, x.max() * 1.02)
#     fits = adata.layers.keys() if fits == 'all' else fits
#     fits = [fit for fit in fits if 'velocity' in fit]
#     for fit in fits:
#         linestyle = '--' if 'stochastic' in fit else '-'
#         pl.plot(xnew, adata.var[fit+'_gamma'][ix] / adata.var[fit+'_beta'][ix] * xnew
#                 + adata.var[fit+'_offset'][ix] / adata.var[fit+'_beta'][ix], c='k', linestyle=linestyle)
#
#     if show: pl.show()
#     else: return ax
コード例 #3
0
ファイル: settings.py プロジェクト: mgood2/scvelo
def set_rcParams_scvelo(fontsize=8, color_map=None):
    """Set matplotlib.rcParams to scvelo defaults."""

    # dpi options (mpl default: 100, 100)
    rcParams['figure.dpi'] = 100
    rcParams['savefig.dpi'] = 150

    # figure (mpl default: 0.125, 0.96, 0.15, 0.91)
    rcParams['figure.figsize'] = (7, 5)
    rcParams['figure.subplot.left'] = 0.18
    rcParams['figure.subplot.right'] = 0.96
    rcParams['figure.subplot.bottom'] = 0.15
    rcParams['figure.subplot.top'] = 0.91

    # lines (defaults:  1.5, 6, 1)
    rcParams['lines.linewidth'] = 1.5  # the line width of the frame
    rcParams['lines.markersize'] = 6
    rcParams['lines.markeredgewidth'] = 1

    # font
    rcParams['font.sans-serif'] = \
        ['Arial', 'Helvetica', 'DejaVu Sans',
         'Bitstream Vera Sans', 'sans-serif']

    fontsize = fontsize
    labelsize = 0.9 * fontsize

    # fonsizes (mpl default: 10, medium, large, medium)
    rcParams['font.size'] = fontsize
    rcParams['legend.fontsize'] = labelsize
    rcParams['axes.titlesize'] = fontsize
    rcParams['axes.labelsize'] = labelsize

    # legend (mpl default: 1, 1, 2, 0.8)
    rcParams['legend.numpoints'] = 1
    rcParams['legend.scatterpoints'] = 1
    rcParams['legend.handlelength'] = 0.5
    rcParams['legend.handletextpad'] = 0.4

    # color cycle
    rcParams['axes.prop_cycle'] = default_palette()

    # axes
    rcParams['axes.linewidth'] = 0.8
    rcParams['axes.edgecolor'] = 'black'
    rcParams['axes.facecolor'] = 'white'

    # ticks (mpl default: k, k, medium, medium)
    rcParams['xtick.color'] = 'k'
    rcParams['ytick.color'] = 'k'
    rcParams['xtick.labelsize'] = labelsize
    rcParams['ytick.labelsize'] = labelsize

    # axes grid (mpl default: False, #b0b0b0)
    rcParams['axes.grid'] = False
    rcParams['grid.color'] = '.8'

    # color map
    rcParams['image.cmap'] = rcParams[
        'image.cmap'] if color_map is None else color_map

    # frame (mpl default: True)
    global _frameon
    _frameon = False