import matplotlib.pyplot as plt
import numpy as np
from scipy.interpolate import make_interp_spline
# Data for r versus g(r)
data = np.array([
[1.250, 0.000], [2.083, 12.892], [2.917, 6.685], [3.750, 3.223],
[4.583, 5.157], [5.417, 0.955], [6.250, 3.683], [7.083, 1.611],
[7.917, 1.592], [8.750, 1.891], [9.583, 0.000], [10.417, 2.328],
[11.250, 0.915], [12.083, 1.009], [12.917, 0.917], [13.750, 1.041],
[14.583, 0.892], [15.417, 0.637], [16.250, 1.024], [17.083, 0.645],
[17.917, 0.604], [18.750, 0.852], [19.583, 0.292], [20.417, 0.821],
[21.250, 0.605], [22.083, 0.661], [22.917, 0.472], [23.750, 0.658],
[24.583, 0.470]
])
# Extract r and g(r)
r = data[:, 0]
g_r = data[:, 1]
# Create a smooth spline for the data points
r_smooth = np.linspace(r.min(), r.max(), 300)
spline = make_interp_spline(r, g_r, k=3) # k=3 for cubic spline
g_r_smooth = spline(r_smooth)
# Create a 2D freehand line plot
plt.figure(figsize=(10, 6))
plt.plot(r_smooth, g_r_smooth, linestyle='-', color='blue')
# Plot original points for reference
plt.scatter(r, g_r, color='red', zorder=5)
# Set labels and title
plt.xlabel('r')
plt.ylabel('g(r)')
plt.title('r vs g(r)')
plt.grid(True)
# Show the plot
plt.show()