I am currenlty working on a plot containing two sets of data and fitting linear regression to them. I have a problem with timestamps that i need to have in UTC on the plot (originally in unix). I could not find a way to fit a linear function to utc values so I wrote a method to count the number of seconds from midnight to wished hour on my plot - got rid of all of the months and years and plotted it. Those are encapsulated in "time_list_basic". For some reason I am getting the "01" before every timestamp visualised on the plot. [![enter image description here][1]][1] I have tried to use ".strftime('%H:%M')" but it messes up the visualisation of Linear Regression, because it automatically changes the way the x axis is labelled. Same goes for just manually recounting number of seconds to hours and minutes. I did that with:
original_times_purple = [f"{int(time[0]) // 3600:02d}:{(int(time[0]) % 3600) // 60:02d}" for time in purple_times]
Maby there is the way of getting rid of those "01"'s or generally smarter way to fit to the unix while presenting results in utc: i am open for suggestions. Here is my code:
# Separate purple and blue points
purple_times = time_list_basic[:4]
purple_times = np.array([midnight_finder(time) for time in purple_times]).reshape(-1,1)
purple_diameters = np.array(present_diameters[:4])
blue_times = time_list_basic[4:]
blue_times = np.array([midnight_finder(time) for time in blue_times]).reshape(-1,1)
blue_diameters = np.array(present_diameters[4:])
model_blue = LinearRegression()
model_purple = LinearRegression()
model_blue.fit(blue_times,blue_diameters)
model_purple.fit(purple_times,purple_diameters)
y_pred_blue = model_blue.predict(blue_times)
y_pred_purple = model_purple.predict(purple_times)
original_times_blue = [datetime.utcfromtimestamp(int(time[0])) for time in blue_times]
original_times_purple = [datetime.utcfromtimestamp(int(time[0])) for time in purple_times]
print(original_times_blue,original_times_purple)
plt.errorbar(original_times_purple, present_diameters[:4], yerr=present_diameters_sizing_errors [:4], fmt='^', color='purple', label='First Four Points')
plt.errorbar(original_times_blue, present_diameters[4:], yerr=present_diameters_sizing_errors [4:], fmt='o', color='blue', label='Rest of the Points')
plt.plot(original_times_purple, y_pred_purple, color='purple', label="title")
plt.plot(original_times_blue, y_pred_blue, color='blue', label="title")
plt.grid(True, linestyle='--', alpha=0.7)
plt.xticks(rotation=45)
plt.xticks(rotation=45)
# Title and labels
plt.title('title')
plt.xlabel('Time (UTC)')
plt.ylabel('y label')
plt.legend()
# Display the plot
plt.show()```
[1]: https://i.stack.imgur.com/QRkQm.png