wollte ich arithmetische Operationen auf Daten durchzuführen, so umgewandelt ich diese TermineWie kann ich es zurück in das Datetime-Format konvertieren?
idx_1 = 2017-06-07 00:00:00
idx_2 = 2017-07-27 00:00:00
mit Schwimmern,
x1 = time.mktime(idx_1.timetuple()) # returns float of dates
>>> 1496773800.0
x2 = time.mktime(idx_2.timetuple())
>>> 1501093800.0
y1 = 155.98
y2 = 147.07
den folgenden Code verwenden plotten:
import datetime as dt
import time
import numpy as np
import matplotlib.pyplot as plt
x = [x1, x2]
y = [y1, y2]
Difference = x2 - x1 #this helps to end the plotted line at specific point
coefficients = np.polyfit(x, y, 1)
polynomial = np.poly1d(coefficients)
# the np.linspace lets you set number of data points, line length.
x_axis = np.linspace(x1, x2 + Difference, 3) # linspace(start, end, num)
y_axis = polynomial(x_axis)
plt.plot(x_axis, y_axis)
plt.plot(x[0], y[0], 'go')
plt.plot(x[1], y[1], 'go')
plt.show()
Wie matplotlib erstellt werden, um die tatsächlichen Daten auf x-Achse anstelle von Schwimmern zu zeichnen?
Jede Art von Hilfe wird sehr geschätzt.
danken Ihnen für die Zeit nehmen zu beantworten, bin froh :) –