Вот изображение x и y ниже:
x = np.array([6, 3, 5, 2, 1, 4, 9, 7, 8])
y = np.array([2, 1, 3 ,5 ,3 ,9 ,8, 10, 7])
С точками x и y для приведенного выше кода это работает, но с x и y ниже, это не выводит точки как код выше. Я думаю, это потому, что приведенный ниже код x и y слишком велик из числа, может быть?
Вот картинка для кода ниже:
import time, os, matplotlib
import numpy as np
from scipy.signal import argrelextrema
from datetime import datetime
import matplotlib.pyplot as plt
x = np.array([])
y = np.array([113.1350,113.2600,113.6000,113.6600,115.1600,114.7700,118.8100,118.3500,118.5500,118.6150,119.3765,119.3500,119.0000,118.7650,117.9300,118.2100,117.7500,117.4400,117.8450,117.7466,117.4500,116.9600,116.2600,116.8100,116.8950])
for line in np.array([
'2020-04-07 16:00:00','2020-04-07 16:01:00','2020-04-07 16:02:00','2020-04-07 16:03:00','2020-04-07 16:04:00',
'2020-04-07 16:05:00','2020-04-07 16:06:00','2020-04-07 16:07:00','2020-04-07 16:08:00','2020-04-07 16:09:00',
'2020-04-07 16:10:00','2020-04-07 16:11:00','2020-04-07 16:12:00','2020-04-07 16:13:00','2020-04-07 16:14:00',
'2020-04-07 16:15:00','2020-04-07 16:16:00','2020-04-07 16:17:00','2020-04-07 16:18:00','2020-04-07 16:19:00',
'2020-04-07 16:20:00','2020-04-07 16:21:00','2020-04-07 16:22:00','2020-04-07 16:23:00','2020-04-07 16:24:00',]):
d=str(line).replace('T',' ')
p='%Y-%m-%d %H:%M:%S'
epoch = int(time.mktime(time.strptime(d,p)))
x = np.append(x, epoch)
# sort the data in x and rearrange y accordingly
sortId = np.argsort(x)
x = x[sortId]
y = y[sortId]
# this way the x-axis corresponds to the index of x
plt.plot(x-1, y)
plt.show()
maxm = argrelextrema(y, np.greater) # (array([1, 3, 6]),)
minm = argrelextrema(y, np.less) # (array([2, 5, 7]),)
from scipy.signal import find_peaks
peaks, _ = find_peaks(y)
troughs, _ = find_peaks(-y)
# this way the x-axis corresponds to the index of x
plt.plot(x-1, y)
plt.plot(peaks, y[peaks], "x")
# plt.plot(troughs, y[troughs], "x")
plt.show()