Created
September 6, 2024 23:22
-
-
Save yuhanz/995e57438af0619d9d8a216ceb43530a to your computer and use it in GitHub Desktop.
Correlate 2 series.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import scipy.signal | |
# Create some data points for the curves | |
x = np.linspace(0, 10, 100) # 100 points between 0 and 10 | |
y1 = np.sin(x) # First curve (sine wave) | |
y2 = np.cos(x) # Second curve (cosine wave) | |
y3 = scipy.signal.correlate(y1, y2, mode = 'same') | |
# Create the plot | |
plt.figure(figsize=(8, 6)) | |
# Plot the first curve | |
plt.plot(x, y1, label='sin(x)', color='blue', linewidth=2) | |
# Plot the second curve | |
plt.plot(x, y2, label='cos(x)', color='red', linestyle='--', linewidth=2) | |
# Plot the second curve | |
plt.plot(x, y3, label='correlate', color='yellow', linewidth=2) | |
# Add labels and title | |
plt.xlabel('x-axis') | |
plt.ylabel('y-axis') | |
plt.title('Plot of sin(x) and cos(x)') | |
# Add a legend to differentiate between the curves | |
plt.legend() | |
# Display the plot | |
plt.grid(True) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment