import plotly.graph_objects as go
import numpy as np
import json
import datetime
with open('ELIX.json') as json_file:
data = json.load(json_file)
Date=[]
Val=[]
for item in data['Elements']:
for sub_item in item['TimeSpans']:
iso_day = datetime.datetime.strptime(item['Date'], '%Y-%m-%dT%H:%M:%S').isocalendar()
Date.append(iso_day)
for item in data['Elements']:
for sub_item in item['TimeSpans']:
Val.append(sub_item['Value'])
X=[]
Y=[]
for i in range(len(Date)):
if(Date[i][0]==2017):
X.append(Date[i])
Y.append(Val[i])
fig1 = go.Figure()
fig1.add_trace(
go.Scattergl(
x = X,
y = Y
)
)
fig1.update_layout(title_text='Time Series',
xaxis_rangeslider_visible=False)
fig1.show()
我正在尝试绘制数据并以单一直线的方式给出奇怪的结果。我的数据在列表X []中:
[[2017, 1, 1], [2017, 1, 1], [2017, 1, 2] ....
Y []:
[41.18, 37.34, 36.04...
最后,X中的数据重复24次(1),因为该数据持续24小时,然后移至第二天。如何正确绘制?