Graph using local time instead of GMT time

2
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from datetime import datetime, timedelta


x = []
y = []

dataset = open("datasetDdos10Abril2017_unixtime.csv","r") ##separacao no csv eh por virgulas

for line in dataset:
    line = line.strip() #23,24\n -> 23,24 retira a quebra de linha
    X,Y = line.split(",") #separador eh a virgula
    x.append( float(X))
    y.append(float (Y))

dataset.close()


##
##x = [1491828000,1491828180,1491828360,1491828540,1491828720,1491828900,1491829080,1491829260,1491829440,1491829620,1491829800,1491829980,1491830160]
##
##y = [5284,4856,4880,4854,4903,4806,4873,4910,4914,4914,4944,4751,4863]
##

#k=datetime.now()
#k = datetime.fromtimestamp(x)
x1 = [datetime.now() + timedelta(microseconds=d/10) for d in x]


plt.gca().xaxis.set_major_formatter(dates.DateFormatter('%m/%d/%Y %H:%M:%S'))

plt.plot(x1, y, 'ro')

plt.title("Gráfico do número de Conexoes por segundo")
plt.ylabel("Numero de conexões por segundo")
plt.xlabel('Tempo')
plt.gcf().autofmt_xdate()
plt.show()

The generated graphic was as follows:

The value 1491828000 (unix time) corresponds to April 10, 2017 9:40:00 AM (local time)

How to make the chart appear on 10/04/2017 9:40:00 instead of the time and date of now (datetime.now ())?

    
asked by anonymous 28.05.2017 / 06:37

1 answer

2

Just switch the conversion here:

x1 = [datetime.now() + timedelta(microseconds=d/10) for d in x]

To:

x1 = [datetime.datetime.fromtimestamp(int(d)) for d in x]
    
28.05.2017 / 06:41