PyComplexHeatmap.utils module

Utility functions, for internal use.

PyComplexHeatmap.utils.axis_ticklabels_overlap(labels)[source]

Return a boolean for whether the list of ticklabels have overlaps.

Parameters:

labels (list of matplotlib ticklabels) –

Returns:

overlap – True if any of the labels overlap.

Return type:

boolean

PyComplexHeatmap.utils.cal_legend_width(legend_list)[source]
PyComplexHeatmap.utils.cluster_labels(labels=None, xticks=None, majority=True)[source]

Merge the adjacent labels into one.

Parameters:
  • labels (a list of labels.) –

  • xticks (a list of x or y ticks coordinates.) –

  • majority (if majority=True, keep the labels with the largest clusters.) –

Returns:

labels,ticks

Return type:

merged labels and ticks coordinates.

Examples

labels=[‘A’,’A’,’B’,’B’,’A’,’C’,’C’,’B’,’B’,’B’,’C’] xticks=list(range(len(labels))) new_labels,x=cluster_labels(labels,xticks)

PyComplexHeatmap.utils.comb(n, k)[source]
PyComplexHeatmap.utils.define_cmap(plot_data, vmin=None, vmax=None, cmap=None, center=None, robust=True, na_col='white')[source]

Use some heuristics to set good defaults for colorbar and range.

PyComplexHeatmap.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

PyComplexHeatmap.utils.evaluate_bezier(points, total=50)[source]

ref: https://www.aiuai.cn/aifarm1570.html

Parameters:
  • points

  • total

PyComplexHeatmap.utils.getControlPoints(p1, p4, axis=0)[source]

A diagonal in this context is a quadratic bezier with the control points positioned halfway between the start and end points but on the same axis.

Parameters:
  • p0

  • p2

PyComplexHeatmap.utils.get_bezier_curve(points)[source]
PyComplexHeatmap.utils.get_colormap(cmap)[source]
PyComplexHeatmap.utils.plot_cmap_legend(cax=None, ax=None, cmap='turbo', label=None, kws=None, label_side='right')[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 (kws passed to plt.colorbar.) –

  • label_side (right or left.) –

Returns:

cbar

Return type:

axes of legend

PyComplexHeatmap.utils.plot_color_dict_legend(D=None, ax=None, title=None, color_text=True, label_side='right', kws=None)[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

PyComplexHeatmap.utils.plot_legend_list(legend_list=None, ax=None, space=0, legend_side='right', y0=None, gap=2, delta_x=None, legend_width=None, legend_vpad=5, cmap_width=4.5, verbose=1)[source]

Plot all lengends for a given legend_list.

Parameters:
  • legend_list (a list including [handles(dict) / cmap / markers dict, title, legend_kws, height, legend_type]) –

  • ax (axes to plot.) –

  • space (unit is pixels.) –

  • legend_side (right, or left) –

  • y0 (the initate coordinate of y for the legend.) –

  • gap (gap between legends, default is 2mm.) –

  • legend_width (width of the legend, default is 4.5mm.) –

Return type:

legend_axes,boundry

PyComplexHeatmap.utils.plot_marker_legend(obj=None, ax=None, title=None, color_text=True, label_side='right', kws=None)[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

PyComplexHeatmap.utils.to_utf8(obj)[source]

Return a string representing a Python object. Strings (i.e. type str) are returned unchanged. Byte strings (i.e. type bytes) are returned as UTF-8-decoded strings. For other objects, the method __str__() is called, and the result is returned as a string.

Parameters:

obj (object) – Any Python object

Returns:

s – UTF-8-decoded string representation of obj

Return type:

str

PyComplexHeatmap.utils.use_pch_style()[source]