Untitled

mail@pastecode.io avatar
unknown
plain_text
12 days ago
1.2 kB
1
Indexable
Never
import matplotlib.pyplot as plt

# Create a new figure and axis for the SSD
fig, ax = plt.subplots(figsize=(12, 6))

# Define the objects involved and their positions
objects = ["Customer", "Click & Collect eStore", "Payment System", "Bank"]
positions = [1, 3, 5, 7]

# Draw lifelines for each object
for i, obj in enumerate(objects):
    ax.text(positions[i], 5.5, obj, ha="center", va="center", fontsize=12, fontweight="bold")
    ax.plot([positions[i], positions[i]], [5, 0.5], linestyle="--", color="gray")

# Define the messages between objects and their positions
messages = [
    ("Enter Payment Details", 0, 1),
    ("Submit Payment", 1, 2),
    ("Request Authorization", 2, 3),
    ("Authorize Payment", 3, 2),
    ("Confirm Payment", 2, 1)
]
y_positions = [4, 3.5, 3, 2.5, 2]

# Annotate the diagram with the messages
for i, (msg, start, end) in enumerate(messages):
    ax.annotate(msg, xy=(positions[start], y_positions[i]), xytext=(positions[end], y_positions[i]), 
                arrowprops=dict(arrowstyle="->", lw=1.5))

# Set limits and remove the axes for a cleaner look
ax.set_xlim(0, 8)
ax.set_ylim(0, 6)
ax.axis('off')

# Display the SSD
plt.show()
Leave a Comment