alphapepttools.pl.label_plot#
- alphapepttools.pl.label_plot(ax, x_values, y_values, labels, x_anchors=None, label_kwargs=None, line_kwargs=None, label_parser=None, y_display_start=1, y_padding_factor=3)#
Add labels to a 2D axes object
Add labels to a plot based on x and y coordinates. The labels are either placed near the datapoint using the automatic dodging function from adjust_text or anchored to the left or right of the plot, where labels below the splitpoint are anchored to the left and labels above the splitpoint are anchored to the right.
- Parameters:
ax (plt.Axes) – Matplotlib axes object to add the labels to.
x_values (list | np.ndarray) – x-coordinates of the labels.
y_values (list | np.ndarray) – y-coordinates of the labels.
labels (list[str] | np.ndarray) – Labels to add to the plot.
x_anchors (list[int | float] | np.ndarray | None, optional) – x-coordinates of the anchors to use for the labels. If None, labels are placed at the x-coordinates of the data points. By default None.
label_kwargs (dict | None, optional) – Additional keyword arguments for the label text, by default None.
line_kwargs (dict | None, optional) – Additional keyword arguments for the line connecting the label to the data point, by default None.
label_parser (Callable | None, optional) – Function to parse the labels, by default None. This is useful to convert labels from a computation-context to presentation context, e.g. a column like upregulated_proteins could be shown as “Upregulated Proteins” in the plot.
y_display_start (float, optional) – Starting point for the y-coordinates of the labels, by default 1. This is used to determine the spacing between labels. The y-coordinates of the labels are adjusted to be evenly spaced between the min and max y-coordinates at that anchor. This is useful for avoiding label overlap.
y_padding_factor (float, optional) – Factor to increase or decrease how far apart labels are spread in the y-direction when stacked into a column over x-anchors
- Return type: