probly.visualization.credal.plot_3d

Plotting for 3 class probabilities.

Classes

TernaryVisualizer()

Class to create ternary visualization.

class probly.visualization.credal.plot_3d.TernaryVisualizer[source]

Bases: object

Class to create ternary visualization.

draw_mle_prob_line(probs, ax)[source]

Draw probability axes for MLE for better readability.

Parameters:
  • probs (np.ndarray) – Array of probability vectors used to compute the MLE.

  • ax (Axes) – Matplotlib Axes on which the MLE point and lines are drawn.

Return type:

None

label_corners_and_vertices(ax, v1, v2, v3, labels)[source]

Label the corners and vertices of a simplex.

Parameters:
  • ax (Axes) – Matplotlib Axes on which the labels are drawn.

  • v1 (np.ndarray) – Coordinates of the first vertex.

  • v2 (np.ndarray) – Coordinates of the second vertex.

  • v3 (np.ndarray) – Coordinates of the third vertex.

  • labels (list[str]) – Text labels for the three vertices, ordered as (v1, v2, v3).

Return type:

None

plot_convex_hull(probs, ax=None)[source]

Draw the convex hull around the points.

Handles special cases: - 1 point (degenerate) - 2 points (line segment) - >= 3 points (polygon)

Parameters:
  • probs (np.ndarray) – Array of probabilities.

  • ax (Axes | None) – Axes to draw on.

  • facecolor – Color of the convex hull.

  • alpha – Opacity of the convex hull.

  • edgecolor – Color of the outline.

  • linewidth – Width of the convex hull.

Returns:

Plot with convex hull.

Return type:

Axes

plot_minmax_lines(probs, ax)[source]

Draw min/max probability lines for each class.

Up to 6 lines total (min & max for 3 classes).

Parameters:
  • probs (np.ndarray) – Array of probability vectors used to compute min/max values.

  • ax (Axes) – Matplotlib Axes on which the envelope lines are drawn.

Return type:

None

probs_to_coords_3d(probs)[source]

Convert ternary probabilities to 2D coordinates.

Parameters:

probs (ndarray) – Probability vector for 3 classes.

Returns:

Tuple containing the 2D coordinates as float.

Return type:

tuple[float, float]

ternary_plot(probs, labels, title, credal_flag, mle_flag, minmax_flag, ax=None, **scatter_kwargs)[source]

Plot ternary scatter points.

Parameters:
  • probs (np.ndarray) – Probability vector for 3 classes.

  • labels (list[str]) – The labels for the ternary points.

  • title (str) – Title of the plot.

  • mle_flag (bool) – Flag to indicate whether median of probabilities is shown.

  • credal_flag (bool) – Flag to indicate whether convex hull is shown.

  • minmax_flag (bool) – Bool defaulted to true, which optionally draws upper and lower probability envelopes.

  • scatter_kwargs (Any) – Keyword arguments passed to scatter_kwargs.

  • ax (Axes | None) – Axes to draw the plot on. If None, a new Axes is created.

Returns:

Ternary plot with scattered points.

Return type:

Axes