Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import pandas as pd
- import stumpy
- import numpy as np
- data = pd.read_csv('https://docs.google.com/spreadsheets/d/1SQfhz7_FLaA7aADKdMrf2SL1p2TgQQfnH-earg1eOCY/export?gid=0&format=csv')
- def min_max_scaling(column):
- min_val = column.min()
- max_val = column.max()
- normalized_column = (column - min_val) / (max_val - min_val)
- return normalized_column
- data['price'] = min_max_scaling(data['price'])
- data['Market Cap'] = min_max_scaling(data['Market Cap'])
- first_data = data["price"]
- second_data = data["Market Cap"]
- m = 30
- Q = first_data.tail(30)
- T = second_data
- distance_profile = stumpy.mass(Q, T, normalize=True)
- idx = np.argmin(distance_profile)
- time_series = first_data
- # Number of latest points to highlight
- highlight_points = 30
- # Range to mark
- start_range = idx
- end_range = idx + m
- # Create the first plot with the gray rectangle for the latest 30 values
- plt.figure(figsize=(10, 6))
- plt.subplot(2, 1, 1)
- plt.plot(time_series, label='Time Series')
- latest_data = time_series[-highlight_points:]
- x_coordinates = np.arange(len(time_series) - highlight_points, len(time_series))
- y_min = np.min(time_series)
- y_max = np.max(time_series)
- rect = plt.Rectangle(
- (x_coordinates[0], y_min),
- highlight_points,
- y_max - y_min,
- fill=True,
- color='gray',
- alpha=0.5,
- )
- plt.gca().add_patch(rect)
- plt.xlabel('Time')
- plt.ylabel('Value')
- plt.title('Time Series with Gray Rectangle for Latest 30 Values (first_data)')
- plt.legend()
- # Create the second plot with the gray rectangle for the specified range
- plt.subplot(2, 1, 2)
- plt.plot(second_data, label='Time Series')
- plt.axvspan(start_range, end_range, color='gray', alpha=0.5)
- plt.xlabel('Time')
- plt.ylabel('Value')
- plt.title('The other graph in which I have to find the similar pattern (second_data)')
- plt.legend()
- # Adjust layout
- plt.tight_layout()
- # Show the plots
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement