import matplotlib.pyplot as plt
import numpy as np

# File names (update paths if necessary)
file1 = "data-xy1.txt"
file2 = "data-xy2.txt"

# Function to load data from a two-column text file
def load_data(filename):
    data = np.loadtxt(filename)
    x = data[:, 0]
    y = data[:, 1]
    return x, y

# Load both datasets
x1, y1 = load_data(file1)
x2, y2 = load_data(file2)

# Create the plot
plt.figure(figsize=(10, 6))

# Plot first dataset (e.g., as a line)
plt.plot(x1, y1, label='Dataset 1', linewidth=1.5, alpha=0.7)

# Plot second dataset (e.g., as a scatter or line)
plt.plot(x2, y2, label='Dataset 2', linewidth=1.5, alpha=0.7)

# Optional: add markers if points are sparse
# plt.plot(x1, y1, 'o', markersize=2, label='Dataset 1')
# plt.plot(x2, y2, 's', markersize=2, label='Dataset 2')

# Labels and legend
plt.xlabel('X coordinate')
plt.ylabel('Y coordinate')
plt.title('Comparison of two datasets')
plt.legend()
plt.grid(True, linestyle='--', alpha=0.5)

# Adjust layout and display
plt.tight_layout()
plt.show()