adataviz.utils module

class adataviz.utils.TextWithCircleHandler(marker_text='', label_text='', text_kws={}, **kwargs)[source]

Bases: HandlerBase

create_artists(legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans)[source]

Return the legend artists generated.

Parameters:
  • legend (~matplotlib.legend.Legend) – The legend for which these legend artists are being created.

  • orig_handle (~matplotlib.artist.Artist or similar) – The object for which these legend artists are being created.

  • xdescent (int) – The rectangle (xdescent, ydescent, width, height) that the legend artists being created should fit within.

  • ydescent (int) – The rectangle (xdescent, ydescent, width, height) that the legend artists being created should fit within.

  • width (int) – The rectangle (xdescent, ydescent, width, height) that the legend artists being created should fit within.

  • height (int) – The rectangle (xdescent, ydescent, width, height) that the legend artists being created should fit within.

  • fontsize (int) – The fontsize in pixels. The legend artists being created should be scaled according to the given fontsize.

  • trans (~matplotlib.transforms.Transform) – The transform that is applied to the legend artists being created. Typically from unit coordinates in the handler box to screen coordinates.

adataviz.utils.density_contour(ax, data, x, y, groupby=None, c='lightgray', single_contour_pad=1, linewidth=1, palette=None)[source]
adataviz.utils.despine(fig=None, ax=None, top=True, right=True, left=False, bottom=False)[source]

Remove the top and right spines from plot(s).

Parameters:
  • fig (matplotlib figure, optional) – Figure to despine all axes of, defaults to the current figure.

  • ax (matplotlib axes, optional) – Specific axes object to despine. Ignored if fig is provided.

  • top (boolean, optional) – If True, remove that spine.

  • right (boolean, optional) – If True, remove that spine.

  • left (boolean, optional) – If True, remove that spine.

  • bottom (boolean, optional) – If True, remove that spine.

Return type:

None

adataviz.utils.df2stdout(df)[source]
adataviz.utils.get_brain_region_structure()[source]

https://atlas.brain-map.org/ BICAN: https://atlas.brain-map.org/atlasviewer/ontologies/11.json HBA: https://atlas.brain-map.org/atlasviewer/ontologies/7.json

adataviz.utils.level_one_palette(name_list, order=None, palette='auto')[source]
adataviz.utils.mpl_style()[source]
adataviz.utils.normalize_mc_by_cell(use_adata, normalize_per_cell=True, clip_norm_value=10, verbose=1, hypo_score=False)[source]
adataviz.utils.parse_gtf(gtf='gencode.v43.annotation.gtf', outfile=None)[source]
adataviz.utils.parse_json(url)[source]
adataviz.utils.plot_cmap_legend(cax=None, ax=None, cmap='turbo', label=None, kws=None, labelsize=6, linewidth=0.5, ticklabel_size=4)[source]

Plot legend for cmap.

Parameters:
  • cax (Axes into which the colorbar will be drawn.)

  • ax (axes to anchor.)

  • cmap (turbo, hsv, Set1, Dark2, Paired, Accent,tab20,exp1,exp2,meth1,meth2)

  • label (title for legend.)

  • kws (dict) – kws passed to plt.colorbar (matplotlib.figure.Figure.colorbar).

Returns:

cbar

Return type:

axes of legend

adataviz.utils.plot_color_dict_legend(D, ax=None, title=None, color_text=True, kws=None, luminance=0.5)[source]

plot legned for color dict

Parameters:
  • D (a dict, key is categorical variable, values are colors.)

  • ax (axes to plot the legend.)

  • title (title of legend.)

  • color_text (whether to change the color of text based on the color in D.)

  • label_side (right of left.)

  • kws (kws passed to plt.legend.)

Return type:

ax.legend

adataviz.utils.plot_marker_legend(color_dict=None, ax=None, title=None, color_text=True, marker='o', kws=None, luminance=0.5)[source]

plot legned for different marker

Parameters:
  • D (a dict, key is categorical variable, values are marker.)

  • ax (axes to plot the legend.)

  • title (title of legend.)

  • color_text (whether to change the color of text based on the color in D.)

  • label_side (right of left.)

  • kws (kws passed to plt.legend.)

Return type:

ax.legend

adataviz.utils.plot_text_legend(color_dict, code2label, ax=None, title=None, color_text=True, boxstyle='Circle', marker_pad=0.1, legend_kws=None, marker_fontsize=4, text_kws=None, alpha=0.7, luminance=0.5)[source]
adataviz.utils.prepare_color_palette(color_dict=None, outpath='palette.xlsx')[source]

Generating a .xlsx file including all color palette.

Parameters:

colors (dict) – A dict of dict, keys are categorical terms, values are HEX color code

adataviz.utils.read_google_sheet(url=None, **kwargs)[source]
adataviz.utils.serialize(x)[source]
adataviz.utils.tight_hue_range(hue_data, portion)[source]

Automatic select a SMALLEST data range that covers [portion] of the data.

adataviz.utils.zoom_ax(ax, zoom_scale, on='both')[source]

Zoom ax on both x and y-axis.

adataviz.utils.zoom_min_max(vmin, vmax, scale)[source]

Zoom min and max value.