Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plot.py by adding a perfect ladder #63

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions asreviewcontrib/insights/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import matplotlib.pyplot as plt

from asreviewcontrib.insights.algorithms import _erf_values
from asreviewcontrib.insights.algorithms import _recall_values
Expand Down Expand Up @@ -397,6 +398,47 @@ def _add_random_curve(ax, labels, x_absolute, y_absolute):

return ax

def add_perfect_curve(ax: plt.Axes, num_steps: int, x_absolute: bool = False, y_absolute: bool = False) -> plt.Axes:
"""
Adds a ladder-like plot with increasing values to the given matplotlib axis.

Parameters:
ax (plt.Axes): The matplotlib axis to which the plot will be added.
num_steps (int): The number of steps in the ladder plot.
x_absolute (bool): If True, absolute x coordinates are provided. Default is False.
y_absolute (bool): If True, absolute y coordinates are provided. Default is False.

Returns:
plt.Axes: The matplotlib axis with the added plot.
"""
# Generate coordinates for a ladder-like plot
x_coords = list(range(num_steps))
y_coords = list(range(num_steps))

# Extend coordinates for the ladder pattern
x_offset = 1
y_offset = 0
x_coords.extend(i + x_offset for i in range(num_steps))
y_coords.extend(i + y_offset for i in range(num_steps))

# Sort coordinates
coordinates = sorted(zip(x_coords, y_coords), key=lambda x: (x[1], x[0]))
x_coords, y_coords = zip(*coordinates)

# Plot and label points
labels = [str(i + 1) for i in range(num_steps)]
ax.plot(x_coords, y_coords, marker='o')
for label, x, y in zip(labels, x_coords, y_coords):
ax.text(x, y, label, ha='right')

# Set plot title and labels
ax.set_title('Increasing Ladder Plot')
ax.set_xlabel('X Axis')
ax.set_ylabel('Y Axis')

return ax # Return the plot object



def _add_wss_curve(ax, labels, x_absolute=False, y_absolute=False, legend_label=None):
x, y = _wss_values(labels, x_absolute=x_absolute, y_absolute=y_absolute)
Expand Down