I can't get my head around recreating the attached image. I looked into fancy arrows and so on but I can't create the blue and red arrow.
This is what I have so far:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import FancyArrowPatch
from scipy.stats import norm
# Generate random data from a continuous distribution (e.g., normal distribution)
data = np.random.normal(0, 1, 100) # Mean = 0, Standard Deviation = 1
# Calculate the CDF
sorted_data = np.sort(data)
cdf = np.arange(1, len(sorted_data) + 1) / len(sorted_data)
plt.figure(figsize=(8, 6))
plt.plot(sorted_data, cdf, label='Empirical CDF')
# Generate random points on the x and y axes
random_x = np.random.choice(sorted_data, 1)[0]
random_y = np.random.uniform(0, 1, 1)[0]
# Plot arrows
arrow1 = FancyArrowPatch((random_x, 0), (random_x, random_y), color='red', arrowstyle='-|>', mutation_scale=15)
arrow2 = FancyArrowPatch((0, random_y), (random_x, random_y), color='blue', arrowstyle='-|>', mutation_scale=15)
plt.gca().add_patch(arrow1)
plt.gca().add_patch(arrow2)
plt.annotate(f'({random_x:.2f}, {random_y:.2f})', (random_x + 0.1, random_y + 0.02), color='black')
plt.title('Cumulative Distribution Function (CDF) with Arrows')
plt.xlabel('X-axis')
plt.ylabel('Cumulative Probability')
plt.legend()
plt.grid(True)
plt.show()