以下代码应该使用基于两个列表的绘图库绘制图形:ambTime
作为X轴,domv1R1Temps
作为Y轴。
代码如下:
import plotly.graph_objs as go
import plotly.offline as ply
from plotly import tools
ambTime = ['10:32:42.951', '10:32:42.951', '10:32:42.951', '10:32:42.951',
'10:32:42.951', '10:32:42.951', '10:32:42.951', '10:32:42.951',
'10:32:42.951', '10:32:42.951', '10:32:42.951', '10:32:42.951',
'10:32:42.951', '10:32:42.951', '10:32:53.117', '10:32:53.117',
'10:32:53.117', '10:32:53.117', '10:32:53.117', '10:32:53.117',
'10:32:53.117', '10:32:53.117', '10:32:53.117', '10:32:53.117',
'10:32:53.117', '10:32:53.117', '10:32:53.117', '10:32:53.117',
'10:33:03.273', '10:33:03.273', '10:33:03.273', '10:33:03.273',
'10:33:03.273', '10:33:03.273', '10:33:03.273', '10:33:03.273',
'10:33:03.273', '10:33:03.273', '10:33:03.273', '10:33:03.273',
'10:33:03.273', '10:33:03.273', '10:33:13.428', '10:33:13.428',
'10:33:13.428', '10:33:13.428', '10:33:13.428', '10:33:13.428',
'10:33:13.428', '10:33:13.428', '10:33:13.428', '10:33:13.428',
'10:33:13.428', '10:33:13.428', '10:33:13.428', '10:33:13.428',
'10:33:23.584', '10:33:23.584', '10:33:23.584', '10:33:23.584',
.
.
.
.
#This list contains 588 items. I shortened the list for the sake of time
.
.
.
.
'10:35:47.713', '10:35:57.884', '10:35:57.884', '10:35:57.884',
'10:35:57.884', '10:35:57.884', '10:35:57.884', '10:35:57.884',
'10:35:57.884', '10:35:57.884', '10:35:57.884', '10:35:57.884',
'10:35:57.884', '10:35:57.884', '10:35:57.884', '10:36:08.695',
'10:36:08.695', '10:36:08.695', '10:36:08.695', '10:36:08.695',
'10:36:08.695', '10:36:08.695', '10:36:08.695', '10:36:08.695',
'10:36:08.695', '10:36:08.695', '10:36:08.742', '10:36:08.742',
'10:36:08.742']
domv1R1Temps = ['27', '27', '27', '27', '27', '27', '27', '27', '27', '28',
'27', '27', '27', '27', '27', '27', '27', '27', '27', '27', '27']
Trace1 = go.Scatter(x= ambTime,y = domv1R1Temps, name='DOMV1 R1
Temperatures')
ambData = [Trace1]
ambLayout = go.Layout(
title='Ambient Temperature',
xaxis=dict(
title='Time',
),
yaxis=dict(
title='Y Axis'
)
)
fig = go.Figure(data=ambData, layout=ambLayout)
ply.plot(fig, filename="Ambient Temperature.html")
当我运行代码时,它会生成一个只有2个变量的图形:请查看图像
但我想让图表显示列表中的每一项。我想知道是否有人知道这里有什么问题?
答案 0 :(得分:0)
我不是剧情的用户,但它似乎只接受了ambTime的前21个元素,因为另一个列表domv1R1Temps只有21个元素。因此,ambTime量表一直持续到10:32:53.117'这是第21个元素。
至于为什么在情节28中没有出现尖峰,我不太确定。也许与设置有关。理想情况下,您应该有一个对应于每个输入X的Y条目。尝试使用较短的21长度ambTime来首先修复情节问题&然后找到一种方法来完成domv1R1Temps中的其余条目。
答案 1 :(得分:0)
通常在积分不平衡时发生。我尝试了代码,并对每个代码提出了相同的观点,并且效果很好。当您从图形的任何一点都丢失甚至一个值时,对于大型数据文件来说,这可能有点乏味。
import plotly.graph_objs as go
import plotly.offline as ply
from plotly import tools
ambTime = ['10:32:42.951', '10:32:42.951', '10:32:42.951', '10:32:42.951',
'10:32:42.951', '10:32:42.951', '10:32:42.951', '10:32:42.951',
'10:32:42.951', '10:32:42.951', '10:32:42.951', '10:32:42.951',
'10:32:42.951', '10:32:42.951', '10:32:53.117', '10:32:53.117',
'10:32:53.117', '10:32:53.117', '10:32:53.117', '10:32:53.117',
'10:32:53.117', '10:32:53.117', '10:32:53.117', '10:32:53.117',
'10:32:53.117', '10:32:53.117', '10:32:53.117', '10:32:53.117',
'10:33:03.273', '10:33:03.273', '10:33:03.273', '10:33:03.273',
'10:33:03.273', '10:33:03.273', '10:33:03.273', '10:33:03.273',
'10:33:03.273', '10:33:03.273', '10:33:03.273', '10:33:03.273',
'10:33:03.273', '10:33:03.273', '10:33:13.428', '10:33:13.428',
'10:33:13.428', '10:33:13.428', '10:33:13.428', '10:33:13.428',
'10:33:13.428', '10:33:13.428', '10:33:13.428', '10:33:13.428',
'10:33:13.428', '10:33:13.428', '10:33:13.428', '10:33:13.428',
'10:33:23.584', '10:33:23.584', '10:33:23.584', '10:33:23.584',
'10:35:47.713', '10:35:57.884', '10:35:57.884', '10:35:57.884',
'10:35:57.884', '10:35:57.884', '10:35:57.884', '10:35:57.884',
'10:35:57.884', '10:35:57.884', '10:35:57.884', '10:35:57.884',
'10:35:57.884', '10:35:57.884', '10:35:57.884', '10:36:08.695',
'10:36:08.695', '10:36:08.695', '10:36:08.695', '10:36:08.695',
'10:36:08.695', '10:36:08.695', '10:36:08.695', '10:36:08.695',
'10:36:08.695', '10:36:08.695', '10:36:08.742', '10:36:08.742',
'10:36:08.742']
domv1R1Temps = ['27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'28', '28', '28', '28',
'28', '28', '28', '28',
'28', '27', '27', '27',
'28', '27', '27', '27',
'28', '27', '27', '27',
'28', '27', '27', '27',
'28', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27', '27', '27', '27',
'27']
Trace1 = go.Scatter(x= ambTime,y = domv1R1Temps, name='DOMV1 R1 Temperatures')
ambData = [Trace1]
ambLayout = go.Layout(
title='Ambient Temperature',
xaxis=dict(
title='Time',
),
yaxis=dict(
title='Y Axis'
)
)
fig = go.Figure(data=ambData, layout=ambLayout)
ply.plot(fig, filename="Ambient Temperature.html")